如何配置 Web.Config 文件以允许自定义 404 处理,同时仍显示页面 500 错误详细信息?

9 iis .net web.config asp-classic

为了自定义 404 处理并根据托管公司的建议,我们目前正在使用以下 web.config 设置。但是,我们很快意识到,使用此配置,任何页面错误(500 错误)也会被​​重定向到此自定义错误页面。如何修改此配置文件,以便我们可以继续使用自定义文件处理 404,同时仍然能够查看页面错误?

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultPath="/Custom404.html" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/Custom404.html" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
<system.web>
<customErrors mode="On">
<error statusCode="404" redirect="/Custom404.html" />
</customErrors>
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)

Aye*_*eji 6

尝试这个 -

<configuration>
   <system.webServer>
      <httpErrors errorMode="Custom" defaultResponseMode="File" >
         <remove statusCode="404" />
         <remove statusCode="500" />
         <error statusCode="404" 
            path="404.html" />
         <error statusCode="500" 
            path="500.html" />
       </httpErrors>
   </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

404错误页面是404.html,它位于我的根目录中,500页面也是如此


小智 1

只需为 500 个错误添加另一个值即可。

<customErrors mode="On">
<error statusCode="404" redirect="/Custom404.html" />
<error statusCode="500" redirect="/Custom500.html" />
</customErrors>
Run Code Online (Sandbox Code Playgroud)