【问题标题】:invalid or unknown .aspx pages do not trigger 404, and instead display marker file text无效或未知的 .aspx 页面不会触发 404,而是显示标记文件文本
【发布时间】:2014-03-25 00:18:12
【问题描述】:

在我的 Web 服务器上,如果我访问一个不存在的页面,它会生成正确的 404,除非该页面以 .aspx 结尾。如果无效的 url 以 .aspx 结尾,IIS 会生成标记文件错误:

"这是预编译工具生成的标记文件,请勿删除!"

而不是正确的 404。如何让 IIS 为未知或无效的 .aspx 页面显示/提供 404?

例如:

http://www.mysite.com/iDontExist.txt --> 生成正确的 404 http://www.mysite.com/iDontExist.aspx --> 标记文件错误而不是 404

有什么想法吗?

【问题讨论】:

    标签: asp.net file iis marker


    【解决方案1】:

    您需要通过 web.config 打开客户错误

     <configuration>
      <system.web>
        <customErrors defaultRedirect="GenericError.html" mode="On">
          <error statusCode="404" redirect="PageNotFound.html"/>
        </customErrors>
      </system.web>
    </configuration>
    

    更多信息请访问MSDN

    【讨论】:

    • 我已经设置了 customErrors。它不适用于 .aspx 页面。它适用于“.aspx”之外的所有其他文件扩展名。
    【解决方案2】:

    诀窍是将 customErrors 标签的“重定向模式”设置为“ResponseRedirect”而不是“ResponseRewrite”:

    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="customError.aspx" redirectMode="ResponseRedirect">
            <error statusCode="404" redirect="customError404.aspx" />
            <error statusCode="500" redirect="customError500.aspx" />
        </customErrors>
    </system.web>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      • 2018-04-04
      • 1970-01-01
      • 2015-08-04
      相关资源
      最近更新 更多