asp.net所有错误返回404

时间:2019-10-08 17:19:09

标签: c# iis

我创建了一个asp.net应用程序,该应用程序在可视化strudio中进行调试时可以运行。当我在生产服务器上运行该应用程序时,几乎所有东西都可以运行,但是任何异常或错误都返回404页而不是500页,因此我无法调试错误。

httperror日志显示没有错误发生。所有这些都在上一次版本更新之前有效。

web.config文件:

xml version="1.0" encoding="utf-8"?>
<configuration>
    <location path="." inheritInChildApplications="false">
        <system.webServer>
            <handlers>
                <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
            </handlers>
            <aspNetCore processPath=".\SHMSWeb.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
        </system.webServer>
        <system.webServer>
            <httpErrors errorMode="Detailed">
                <remove statusCode="404" subStatusCode="-1" />
            </httpErrors>
            <asp scriptErrorSentToBrowser="true" />
        </system.webServer>
        <system.web>
            <customErrors mode="Off" />
            <compilation debug="true" />
        </system.web>
    </location>
</configuration>

1 个答案:

答案 0 :(得分:0)

如果您使用的是.net Framework,请检查是否具有web.config文件。应该有一个customErrors部分,看起来可能像这样

<customErrors mode="RemoteOnly" defaultRedirect="your404page"></customErrors>

该模式指示发生错误时会发生什么。您有选项RemoteOnlyOnOff。就像您打开了RemoteOnly一样,这意味着在本地会收到错误消息,但是在远程服务器上,错误隐藏在自定义错误页面的后面(您不想向用户显示错误)。

要在生产服务器上打开错误消息,则必须将值设置为Off(注意,它区分大小写!)

相关问题