27

I am trying to streamline my MVC application and deleting as much as possible. Can someone explain to me what this code below does in the web.config file in the root of the application. I have commented it out and still managed to run the application...

<system.webServer>
     
  <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0"/>
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
    </handlers>
    ...

I have looked at this question: ASP.NET MVC 4 and ExtensionlessUrlHandler which has an answer that links to this blog: https://web.archive.org/web/20100611160242/http://blogs.msdn.com/b/tmarq/archive/2010/05/26/how-extensionless-urls-are-handled-by-asp-net-v4.aspx but I don't find it to explain my question.

I am using: IIS 8, ASP.NET MVC 4, .NET 4.5 in both development and production

Bouke
  • 11,768
  • 7
  • 68
  • 102
Oskar
  • 1,597
  • 4
  • 19
  • 38
  • I have edited your title because in your question body doesn't actually ask what said URL handler is or does, and the answer you accepted doesn't explain it, either (hence, apparently, what it is or does is not what you were interested in). – O. R. Mapper Mar 26 '20 at 10:19

2 Answers2

26

You should check your web.config file. If the following setting is present

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
  </modules>    
</system.webServer>

Then, it could explain why everything is still working after deleting the ExtensionlessUrlHandler handlers.

By default the runAllManagedModulesForAllRequests is false which means that IIS does not delegate each request to managed (.NET) modules. The core module which knows how to handle extension less URL is named UrlRouting module and it is a managed (not native) module. This means that it doesn't have a chance to handle the request and IIS internally tries to handle it according to its handler mapping configuration. BTW, the default configuration treat the extensionless url as a static resource and therefore fails with 403.14 status code (in most cases)

When runAllManagedModulesForAllRequests is true any request being sent to IIS is directed to any managed module. The UrlRouting module has a change to process the request and delegate it to ASP.NET MVC.

To summarize, when running ASP.NET MVC applications you have two options

  1. runAllManagedModulesForAllRequests is false. The ExtensionlessUrlHandler must be registered
  2. runAllManagedModulesForAllRequests is true. You can delete ExtensionlessUrlHandler from the IIS handlers list
Ori Calvo
  • 426
  • 5
  • 6
  • 1
    I have set modules runAllManagedModulesForAllRequests="false" and deleted the ExtensionlessUrlHandler from the web.config, and restarted the IIS, but it still works for me... – Oskar Mar 24 '15 at 08:54
  • Can you share a simple project that demonstrate the behavior you see? – Ori Calvo Mar 25 '15 at 20:07
  • From the attached web.config it seems as you didn't remove the handlers. You should keep the following markup uncommented – Ori Calvo Mar 28 '15 at 15:23
  • I uncommented the three remove statements and ran and still got a successful response with runAllManagedModulesForAllRequests set to false. To clarify, I am running with IISExpress, the default setting through VS. – Oskar Mar 30 '15 at 11:25
10

IIS express uses different handlers names than IIS

Add the following markup and it should disable the extensionless handlers for IIS express only

<remove name="ExtensionlessUrl-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrl-Integrated-4.0" />
Ori Calvo
  • 426
  • 5
  • 6
  • That did the trick! I was using IIS Express because I was using the default settings in Visual Studio. – Oskar Apr 01 '15 at 06:08