ASP.NET 返回 HTTP 500 而不是 404 [英] ASP.NET returns HTTP 500 instead of 404

查看:49
本文介绍了ASP.NET 返回 HTTP 500 而不是 404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,当访问不存在的路由时,我的 ASP.NET Web 应用程序返回错误 500(显然源自处理程序ExtensionlessUrlHandler-Integrated-4.0").

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.

在我将 <add name=" 中的 path="*." 更改为 path="*" 后,此问题开始出现ExtensionlessUrlHandler-Integrated-4.0" ... 我的 Web.config 文件的行以解决 另一个问题(无法处理最后一个斜杠后有一个点的路由).

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).

我无法将 path 改回 "*.",即使那正是 建议作为另一个问题的解决方案,因为这会带回 另一个问题 - 在最后一个斜杠之后的部分中没有找到带有点的路由.

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.

就像在链接的其他问题中一样,我正在使用 OData.但是,在我的情况下,我根本不知道它应该在路由解析中发挥任何作用,因为我认为我们将它视为在我们的 C# 项目中引用并由我们的一些 Web API 端点.

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"/> 已经在我的 Web.config 文件中设置.

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

我还能做什么 404 返回未知路由extension-ful"路由(即最后一个斜杠后的最后一部分包含一个点的路由)被接受?

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?

我已经设法增加了我的 FREB 日志大小,现在看到有问题的条目是编号 1346,说

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="内部服务器错误", HttpSubStatus="0", ErrorCode="Rekursion zu tief, Stapelüberlauf.(0x800703e9)", ConfigExceptionInfo=""

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 建议删除各种处理程序,这对我没有任何改变.
  • Joe Davis 建议使用 "*." 路径的解决方案,该路径有效,但会导致其他问题,如上所述.
  • 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.

两个答案都参考了我的 Web.config 文件中的 部分,目前看起来像这样:

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>

推荐答案

确保您的 web api 与 '.' 配合使用(点)在路径为 '*.' 的全局处理程序之前添加一个特定的 API 处理程序

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

见下例:

  <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" />        

这篇关于ASP.NET 返回 HTTP 500 而不是 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆