Steps
- Create empty clean ASP.NET Web App - "MyApp". Deselect all options.
- Create HttpModule - "MyHttpModule" (by MSDN example):
using System; using System.Web;
public class MyHttpModule : IHttpModule { public MyHttpModule() { }
public string ModuleName { get { return "MyHttpModule"; } }
public void Dispose() { }
public void Init(HttpApplication app)
{
app.BeginRequest += ProcessBeginRequest;
}
private void ProcessBeginRequest(object source, EventArgs e)
{
var ctx = ((HttpApplication)source).Context;
if (ctx.Request.Path == "/favicon.ico") { return; } // This stuff is handled automatically in current IIS version. So, I wrote this line just in case.
ctx.Response.Write("Processing request from: " + ctx.Request.Url + "<br />");
ctx.Response.Flush();
}
}
-
Include it to web.config:
<system.webServer><modules><add name="MyHttpModule" type="MyHttpModule, MyApp"/></modules></system.webServer> -
Run the app
-
Browser shows that
BeginRequestlistener was triggered twice for single http reques:
Attempts
LogRequestevent listener is executed as expected. But this is not proper name listener for http processing work-
Changes like this one had no result:
app.BeginRequest -= ProcessBeginRequest; app.BeginRequest += ProcessBeginRequest; - Not a favicon.ico thing
Question
Why event handler of single http request was called twice?
How risky it is to start any low-level http request processing with IIS? (that is something more than just logging)
PS: After surfing the internet I'm thinking this is IIS bug. Am I wrong? Of course, for low-level processing of http requests and for maximum performance it's better to self-host the application or use some prepared set of components for self-hosting like Katana. But I wonder if IIS be extended with such stuff safely? Cause I have a bad feeling about it, as now it tells to me stay out of http level, do nothing more than logging there and use IIS configuration only.
Aucun commentaire:
Enregistrer un commentaire