【发布时间】:2013-06-16 01:35:15
【问题描述】:
我正在用 ASP.NET 编写一个应用程序。
我想知道如何在用户键入我的项目中不存在的页面地址时显示自定义错误页面。请问这怎么做?谢谢:)
【问题讨论】:
我正在用 ASP.NET 编写一个应用程序。
我想知道如何在用户键入我的项目中不存在的页面地址时显示自定义错误页面。请问这怎么做?谢谢:)
【问题讨论】:
将以上内容添加到您的 webconfig 中
<configuration>
<system.web>
<customErrors mode="RemoteOnly"
defaultRedirect="~/ErrorPages/Error.aspx">
<error statusCode="404" redirect="~/default.aspx"/>
</customErrors>
</system.web>
【讨论】:
查看 web.config 架构的 the MSDN documentation page for the customErrors element - 提供的示例如下:
<configuration>
<system.web>
<customErrors defaultRedirect="GenericError.htm" mode="RemoteOnly">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
</system.web>
</configuration>
【讨论】:
【讨论】: