views:

24

answers:

2

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 though of a solution - I can write my fucntion in global.asax and call it on page load of other pages but in that solution I need to call it in every page. I would prefer something which is to be done only in global.asax

A: 

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"))
    {
        // ...
    }
}
Darin Dimitrov
A: 

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.

David Waters