Hi I want to know a method that hits for every page in asp.net via global.ascx
Thanks
If you are using Global.asax file then you can use Application_BeginRequest
method.
Sample Code:
///
/// Handles the Start event of the Application control.
///
/// The source of the event.
/// Theinstance containing the event data.
protected void Application_Start(object sender, EventArgs e)
{
}
Check the below link for more details
http://www.dotnetcurry.com/showarticle.aspx?ID=126
Hi,
This is global.asax (not .ascx which are user controls) and you'll find a description of the whole pipeline at
http://msdn.microsoft.com/en-us/library/vstudio/bb470252(v=vs.100).aspx . See perhaps BeginRequest (if you meant each http query) or (Post)MapRequestHandler if you meant each aspx page (you'll have to test which handler it is to find out if this is an ASPX
page).
It's often easier to help when knowing what you are trying to do rather than just what you technically want to use (ie here we know you want a method hit for each ASPX page or each HTTP query but we have no idea about your overall goal). Sometimes it allows
to suggest an alternate and possibly better approach for doing the job or at least to better grasp what you really need.
When I debug Begin request fires more than once. I want execute query for every http call.
Do you mean more than once for each http request or for each page ? Have you tried to see for which url it happens. For example if you load a page, it will happen for the ASPX page but also for each file that could be used by this page (ie CSS, JavaScript
files, image files, handlers etc...).
Use perhaps the browser dev tools and check which http requests are triggered by the browser (for example
https://developer.chrome.com/devtools/docs/network for Chrome). You should have the same count on your server.
This is also why I suggested that knowing what you actually want to do allows to better help. So you want to run something each time an ASPX page and only an ASPX page is hit ?
If this is the case you could:
- use BeginRequest and test the url
- use PostMapRequestHandler and see if this is an ASPX handler
- or does this in a base class for all your ASPX page (and you can define the base class in the web config)
Option 3 would be likely my personal preference (but again I don't know exactly what you want really to do).
It records all page url like js,css etc in a page.
I want to track hit count for each page for a website. insert only aspx page url into DB.
Dont want to insert all unnecessary URL.
Thanks
I have one more question can we use session to get user info in PostMapRequestHandler?
I getting error as null reference
Thanks
沒有留言:
張貼留言