2010-03-25 75 views
0

我需要一個global.asax文件中的函數,當用戶輸入一個頁面url時,它只會被調用一次。得到的Application_BeginRequest在一個頁面調用時間50-60(以呈現頁面的多個請求到服務器。)在global.asax中維護pageViews(asp.net)

我想到了一個解決方案 - 我可以寫我的功能在Global.asax中並調用它的頁面加載其他頁面,但在該解決方案中,我需要在每個頁面中調用它。我喜歡的東西這是隻有在Global.asax中做

回答

0

你可以在Begin_Request功能測試請求URL:

protected void Application_BeginRequest(object sender, EventArgs e) 
{ 
    // Perform some test on the request url that suits your case: 
    if (Request.Url.ToString().EndsWith(".aspx")) 
    { 
     // ... 
    } 
} 
0

您的方法的另一個變化是創建網頁,其中名爲的子類你的全局方法,或者做了工作本身,然後讓你的所有頁面不是直接擴展你的類。

public class AcmePage : Page{ 
    // override/subscribe to one of the page events 
} 
... 
public class HomePage : AcmePage 

如果你只是想算頁面訪問量也可能是值得考慮的預建提供分析服務,如免費google analytics。還有像CoreMetrics等其他人。