mercredi 8 février 2017

IIS calls BeginRequest of HttpModule twice. Is it a bug?

Steps

  1. Create empty clean ASP.NET Web App - "MyApp". Deselect all options.
  2. 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();
}

}

  1. Include it to web.config:

    <system.webServer> <modules> <add name="MyHttpModule" type="MyHttpModule, MyApp"/> </modules> </system.webServer>

  2. Run the app

  3. Browser shows that BeginRequest listener was triggered twice for single http reques:

Singe http request execution with profiler

Attempts

  1. LogRequest event listener is executed as expected. But this is not proper name listener for http processing work
  2. Changes like this one had no result:

    app.BeginRequest -= ProcessBeginRequest;
    app.BeginRequest += ProcessBeginRequest;
    
    
  3. 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