Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicated requests when debugging ASP.NET on IIS Express

I noticed a strange behavior while debugging an ASP.NET Web Application (.NET 4.6.1). Whenever an HTTP error occurs (e.g. 404 or 403) the request get duplicated up to a total of 3 times.

I have tested this singular issue using fiddler, and Intellitrace effectively shows me the three identical requests (even if I send just a single request).

Fiddler Intellitrace

I can see the effects of this issue because any Owin middleware in the pipeline is invoked three times. A simple middleware like this:

app.Use(async (c, n) =>
{
    Debug.WriteLine("HIT!");
    await n.Invoke();
});

Will print three consecutive "HIT!" into the console.

This happens only if the request generates an error, and not if the request is handled by a middleware (e.g. not if the middleware responds with a 2XX status code).

What's going on?

I'm running VS2015 and IIS Express 10 on Win10.

[EDIT] It may be related to my Web.config configuration? I'm adding an excerpt from it.

<system.web>
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1" enableVersionHeader="false" />
</system.web>
<system.webServer>
    <httpProtocol>
        <customHeaders>
            <clear />
        </customHeaders>
        <redirectHeaders>
            <clear />
        </redirectHeaders>
    </httpProtocol>
    <security>
        <requestFiltering removeServerHeader="true" />
    </security>
    <handlers>
        <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
        <remove name="OPTIONSVerbHandler" />
        <remove name="TRACEVerbHandler" />
        <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
like image 857
Federico Dipuma Avatar asked Oct 31 '22 07:10

Federico Dipuma


1 Answers

The issue was caused by multiple handlers trying to manage the unhandled request in IIS Express. I solved it by removing them in Web.config:

<system.webServer>
    <handlers>
        <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
        <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
        <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
        <remove name="ExtensionlessUrl-Integrated-4.0" />
        <remove name="ExtensionlessUrl-ISAPI-4.0_32bit" />
    </handlers>
</system.webServer>
like image 107
Federico Dipuma Avatar answered Nov 15 '22 04:11

Federico Dipuma