2014-08-27 73 views
0

我正在跟蹤ASP.net webforms應用程序中的頁面標題。下面的代碼工作,但page.Title總是拋出一個System.NullReferenceException,即使我正在跟蹤的頁面有一個標題。爲什麼?爲什麼我無法在httpModule中獲得Page.Title?

public class TrackingModule : IHttpModule 
{ 
    public void Init(HttpApplication application) 
    { 
     application.PostAcquireRequestState += new EventHandler(Application_PostAcquireRequestState); 
    } 

    void Application_PostAcquireRequestState(object source, EventArgs e) 
    { 
     if (HttpContext.Current.Handler is Page && HttpContext.Current.Session != null) 
     { 
      Page page = (Page)HttpContext.Current.Handler; 

      Log(page.Title); 
     } 
    } 
} 
+0

你可能會這麼做很快。 – 2014-08-27 18:48:26

+0

你在哪裏得到例外? – 2014-08-27 18:48:58

回答

0

我只能看到它是頁面變量未初始化。 HttpContext.Current.Handler實際上是否包含內存地址或值?如果它給了你一個System.NullReferenceException,那麼它就是 - 標題,或者是標題爲空的東西。

相關問題