【问题标题】:Website gives a white page instead of an 404 error网站提供白页而不是 404 错误
【发布时间】:2012-05-17 18:13:20
【问题描述】:

我有一个很奇怪的问题:

当我访问我网站上不存在的 URL 时,它只会显示一个白页。 Application_Error 事件永远不会运行,用户也不会转移到我们使用的 404 页面。

我需要捕捉 Application_Error 事件,进行一些日志记录和一些重定向。

我无法访问 IIS,因为我在共享 webhotel 上运行我的网站。但是对于我所有其他网站,这都可以正常工作。

这是我的 web.config:

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
    </compilation>
    <pages>
      <controls>
        <add src="~/UC/Filters.ascx" tagName="Filters" tagPrefix="uc2"/>
      </controls>
    </pages>
    <httpRuntime maxRequestLength="1048576" requestValidationMode="2.0"/>
    <customErrors mode="Off" defaultRedirect="ErrorPage.aspx">
      <error statusCode="404" redirect="404-Error.aspx"/>
    </customErrors>
    <sessionState timeout="5000"/>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
      <add name="AjaxToolkit" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </handlers>
    <rewrite>
      <rules>
        <rule name="Redirect domain.com to www" patternSyntax="Wildcard" stopProcessing="true">
          <match url="*"/>
          <conditions>
            <add input="{HTTP_HOST}" pattern="domain.com"/>
          </conditions>
          <action type="Redirect" url="http://www.domain.com/{R:0}"/>
        </rule>
        <!--To always remove trailing slash from the URL-->
        <rule name="Remove trailing slash" stopProcessing="true">
          <match url="(.*)/$"/>
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="{R:1}"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

有什么想法吗?谢谢:-D

【问题讨论】:

    标签: asp.net web-config http-status-code-404


    【解决方案1】:

    将您的自定义错误设置为:

    <customErrors mode="RemoteOnly" defaultRedirect="ErrorPage.aspx">
      <error statusCode="404" redirect="404-Error.aspx"/>
    </customErrors>
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-22
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多