首页 > 解决方案 > ASP页面错误甚至自定义错误模式“ON”

问题描述

我的 web.config 中有自定义错误模式“开启”。但是,对于某些类型的特定 URL,ASPX 错误页面仍然显示

不正常
https://example.com/*~1*%5ca.aspx <-- 返回 404 - 找不到文件或目录。

OK
https://example.com/abc.aspx<-- 可以重定向到自定义页面

我正在使用 Windows Server 2012 Azure。我在注册表中禁用了NtfsDisable8dot3NameCreation,但仍然没有运气。什么可能是根本原因?

我的网络配置

  <customErrors mode="On" defaultRedirect="~/error/Error403.html">
      <error statusCode="400" redirect="~/error/Error400.html" />
      <error statusCode="401" redirect="~/error/Error400.html" />
      <error statusCode="402" redirect="~/error/Error400.html" />      
      <error statusCode="403" redirect="~/error/Error403.html" />
      <error statusCode="404" redirect="~/error/Error404.html" />
      <error statusCode="500" redirect="~/error/Error500.html" />
      <error statusCode="501" redirect="~/error/Error501.html" />
      <error statusCode="502" redirect="~/error/Error502.html" />
      <error statusCode="503" redirect="~/error/Error503.html" />
      <error statusCode="504" redirect="~/error/Error504.html" />
    </customErrors>

 <httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="ExecuteURL">
       <remove statusCode="400" subStatusCode="-1"/>
       <remove statusCode="401" subStatusCode="-1"/>
       <remove statusCode="402" subStatusCode="-1"/>
       <remove statusCode="403" subStatusCode="-1"/>
       <remove statusCode="404" subStatusCode="-1"/>       
       <remove statusCode="500" subStatusCode="-1"/>
       <remove statusCode="501" subStatusCode="-1"/>
       <remove statusCode="502" subStatusCode="-1"/>
       <remove statusCode="503" subStatusCode="-1"/>
       <remove statusCode="504" subStatusCode="-1"/>
      <!--<error statusCode="500" path="error\InternalServerError.htm"/>
      <error statusCode="404" path="error\PageNotFound.htm"/>-->

       <error statusCode="400" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error400.html" />
       <error statusCode="401" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error400.html" />
       <error statusCode="402" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error400.html" />
       <error statusCode="403" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error400.html" />      
      <error statusCode="404" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error404.html" />
      <error statusCode="500" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error500.html" />
       <error statusCode="501" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error501.html" />
       <error statusCode="502" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error502.html" />
       <error statusCode="503" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error503.html" />
     <error statusCode="504" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error504.html" />
    </httpErrors>

标签: asp.netiis

解决方案


我认为你应该得到 400 错误而不是 404 错误,因为“*”不是 .NET 运行时的有效 request.path 并且异常是从 CLR 引发的。这就是为什么 IIS 自定义错误页面永远无法工作的原因。

请尝试将 requestPathInvalidCharacters 设置为 null 或手动为您的运行时指定无效字符。

 <system.web>
    <compilation targetFramework="4.8" />
    <httpRuntime requestPathInvalidCharacters=""/>
        <customErrors mode="RemoteOnly">
            <error redirect="https://www.jokiesd.com/404.aspx" statusCode="404" />
        </customErrors>
  </system.web>

编辑:</p>

我无法在我的 2012 服务器上重现此问题。您是否尝试将 URL 替换为绝对 URL?

在此处输入图像描述


推荐阅读