ASP.NET - IHttpModule.BeginRequest firing 2X, Application_BeginRequest firing 1X -
I am running VS 2008 and .NET 3.5 SP1.
I want to implement hit tracking. One HTTP module in my ASP.NET app is very simple, though I thought, the event of launching my HTTP module is firing twice for every page hit. The site is just too easy ... no security, just a bit of database work Hit one page should be logged one line why this event is firing twice?
In addition, IHttpModule.BeginRequest actually fires a different number to hit the first time when first running (from the closed web browser) for the first time ... 3 times I dynamic for the page To deliver the data, I am killing DB and only for 1 of those pages where DB is not being hit.
It is interesting to note that application_BeginRequest is always firing only once (in Global.SX).
Here is the code:
Using the system; Using System.Data; Using System.Data.Common; Using System.Net; Using System.Web; Using BluHeron.BusinessLayer; Using Microsoft.Practices.EnterpriseLibrary.Data.Sql; Name Location BluHeron.HttpModules {Public class SiteUsage module: IHttpModule {Public Zero Init (HttpApplication httpApp) {httpApp.BeginRequest + = OnBeginRequest; } Fixed Zero OnBeneConst (Object Sender, EventArgues A) {Eugogor. LogSet Usage ((HTTPPeople) Sender) .Context.Request); } Public Zero Extracting () {}} Public Static Class UsageLogger {Public Static Zero LogSiteUsage (HttpRequest R) {string ipAddress = GetHostAddress (Dns.GetHostAddresses (Dns.GetHostName ())); String BrowserWarson = R. Bracer Type; String [] urlChunks = r.RawUrl.Split ('/'); String page = urlChunks [urlChunks.GetLength (0) -1]; SqlDatabase db = new SqlDatabase (Normal.GETConnectionString ()); DB Commmd CMD = DB.GetStreamProx Command ("Log Usage"); Db.AddInParameter (cmd, "IPAddress", SqlDbType.NVarChar, ipAddress); Db.AddInParameter (cmd, "BrowserVersion", SqlDbType.NVarChar, BrowserWarson); Db.AddInParameter (CMD, "PageName", SKLDB type: NVarChar, page); Db.AddInParameter (CMD, "Notes", SqlDbType.NVarChar, ""); Db.ExecuteNonQuery (cmd); } Private Static String GetHostAddress (IPAddress [] addresses) {foreach (IPAddress in IP address) {If (IP toString (.) Length
This may be too late for answers but useful for anyone Other may be I had to face the same problem. BeginRequest event started for each request to start twice. I debug the code and realized that the first trigger for the actual processing request, but the result of the second "favicon.ico" request, at the beginning of the BeginRequest event, favicon.ico terminates the second execution of a simple test method for the request. .
Public Zero Application_BeginRequest (Object Sender, EventArgs e) {HttpApplication app = (HttpApplication) Sender; HttpContext ctx = app.Context; If (ctx.Request.Path == "/favicon.ico") {return; }
Comments
Post a Comment