Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET returns HTTP 500 instead of 404

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>
like image 420
O. R. Mapper Avatar asked Mar 26 '20 10:03

O. R. Mapper


People also ask

Is 500 client or Server Error?

The HTTP status code 500 is a generic error response. It means that the server encountered an unexpected condition that prevented it from fulfilling the request. This error is usually returned by the server when no other error code is suitable.

What is 404 and 500 Error?

500 Internal Server Error - The server encountered an unexpected condition which prevented it from fulfilling the request. 2. 404 Not Found - The server has not found anything matching the Request-URI.

What is an ASP 500 error?

HTTP Error 500 message indicates that a problem has occurred on the Web server that hosts the Web site at the time the error is returned.

What is 404 error asp net?

Best web development and SEO practices dictate that any webpage which does not exist, return an HTTP response code of 404, or Not Found. Basically, this response code means that the URL that you're requesting does not exist.


Video Answer


1 Answers

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" />        
like image 190
Tom Janssen Avatar answered Oct 17 '22 20:10

Tom Janssen