我需要一个global.asax文件中的函数,当用户输入一个页面url时,它只会被调用一次。得到的Application_BeginRequest在一个页面调用时间50-60(以呈现页面的多个请求到服务器。)在global.asax中维护pageViews(asp.net)
我想到了一个解决方案 - 我可以写我的功能在Global.asax中并调用它的页面加载其他页面,但在该解决方案中,我需要在每个页面中调用它。我喜欢的东西这是只有在Global.asax中做
我需要一个global.asax文件中的函数,当用户输入一个页面url时,它只会被调用一次。得到的Application_BeginRequest在一个页面调用时间50-60(以呈现页面的多个请求到服务器。)在global.asax中维护pageViews(asp.net)
我想到了一个解决方案 - 我可以写我的功能在Global.asax中并调用它的页面加载其他页面,但在该解决方案中,我需要在每个页面中调用它。我喜欢的东西这是只有在Global.asax中做
你可以在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"))
{
// ...
}
}
您的方法的另一个变化是创建网页,其中名为的子类你的全局方法,或者做了工作本身,然后让你的所有页面不是直接扩展你的类。
public class AcmePage : Page{
// override/subscribe to one of the page events
}
...
public class HomePage : AcmePage
如果你只是想算页面访问量也可能是值得考虑的预建提供分析服务,如免费google analytics。还有像CoreMetrics等其他人。