用户输入错误的网址时,自定义页面不会显示

时间:2015-07-16 06:43:17

标签: asp.net

我的web.config文件中有以下代码

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>    
  <httpErrors errorMode="Custom" existingResponse="Replace">
    <remove statusCode="404"/>
    <remove statusCode="500"/>
    <error statusCode="404" responseMode="ExecuteURL"
    path="~/ERRORPAGES/Pagenotfound.aspx"/>
    <error statusCode="500" responseMode="ExecuteURL"
    path="~/ERRORPAGES/Pagenotfound.aspx"/>
  </httpErrors> </system.webServer>

我有Pagenotfound.aspx页面当用户输入错误的url时调用它很遗憾它没有调用而是我得到的错误就像 无法找到该资源。   说明:HTTP 404.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,确保拼写正确。

请建议我怎么办?我正在通过visual studio运行我的开发机器来测试它。

1 个答案:

答案 0 :(得分:0)

您似乎需要custom error messages

<configuration>
  <system.web>
    <customErrors defaultRedirect="~/ERRORPAGES/GenericError.aspx" mode="RemoteOnly">
      <error statusCode="404" redirect="~/ERRORPAGES/Pagenotfound.aspx"/>
      <error statusCode="500" redirect="~/ERRORPAGES/Pagenotfound.aspx"/>
    </customErrors>
  </system.web>
</configuration>
  

[customErrors元素]提供有关自定义错误的信息   ASP.NET应用程序的消息。 customErrors元素可以是   在应用程序文件层次结构中的任何级别定义。

请注意,mode标记的customErrors属性是必需的。以下是它的选项:

  

开 - 指定启用自定义错误。如果没有defaultRedirect   指定了属性,用户看到一般错误。自定义错误   显示给远程客户端和本地主机。

     

关闭 - 指定禁用自定义错误。详细的ASP.NET   错误显示给远程客户端和本地主机。

     

RemoteOnly - 指定仅向远程显示自定义错误   客户端,以及ASP.NET错误显示给本地主机。这是   默认值。

所有块引用均来自MSDN的链接文章。