ASP.NET returns HTTP 500 instead of 404

8

For some reason, my ASP.NET web application returns error 500 (apparently originating from handler "ExtensionlessUrlHandler-Integrated-4.0") when a non-existing route is accessed.

This issue has started to occur after I had changed path="*." to path="*" in the <add name="ExtensionlessUrlHandler-Integrated-4.0" ... line of my Web.config file in order to solve another problem (failure to process routes with a dot after the last slash).

I cannot change path back to "*.", even though exactly that is suggested as a solution in another question, because that will bring back the other problem - routes with a dot in the part after the last slash are not found anymore.

Like in that linked other question, I am using OData. However, I am not aware that it should play any role in route resolution in my case at all, because I think we treat it just as an ordinary library that is referenced in our C# projects and invoked by a few of our web API endpoints.

<modules runAllManagedModulesForAllRequests="true"/> is already set in my Web.config file.

What else can I do so 404 is returned for unknown routes and "extension-ful" routes (i.e. routes whose last part after the last slash contains a dot) are accepted?

EDIT: I have managed to increase my FREB log size and now see that the offending entry is number 1346, saying

ModuleName="ManagedPipelineHandler", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="Rekursion zu tief, Stapelüberlauf. (0x800703e9)", ConfigExceptionInfo=""

In English, the error message means: "Recursion too deep, stack overflow."

Therefore, it appears to be the same issue as in another question, however, the answers from there do not help in my case:

  • Philip suggests to remove various handlers, which doesn't change anything for me.
  • Joe Davis suggests the solution with the "*." path, which works, but causes the other problem, as described above.

Both answers refer to the <handlers> section in my Web.config file, which currently looks like this:

<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>
asp.net
routing
routes
iis-10
asked on Stack Overflow Mar 26, 2020 by O. R. Mapper • edited Mar 31, 2020 by O. R. Mapper

1 Answer

0

To make sure your web api works with '.' (dot) add a specific API handler BEFORE the global handler with path '*.'

See below example:

  <add name="ApiURIs-ISAPI-Integrated-4.0-ForApi" path="/api/*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />        
answered on Stack Overflow May 17, 2021 by Tom Janssen

User contributions licensed under CC BY-SA 3.0