开发者

maintain pageViews in global.asax (asp.net)

I need a function in global.asax file which gets called only once when user enter a page url. application_beginrequest gets called 50-60 times in a single page( as to render a page several requests go to server.)

I thought of a solution - I can write my function in global.asax and call it on page load of other pages b开发者_运维知识库ut in that solution I need to call it in every page. I would prefer something which is to be done only in global.asax


You could test the request url in the Begin_Request function:

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"))
    {
        // ...
    }
}


Another variation on your approach would be create a subclass of Page which called your global method, or did the work itself and then have all your pages extend your class not Page directly.

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

If you are just trying to count page views it may be worth looking at the pre built analytics services available, like the free google analytics. There are others around like CoreMetrics etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜