ASP.net自定义错误页面 [英] ASP.net custom error page

查看:59
本文介绍了ASP.net自定义错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现自定义错误页面,我想要做的是拥有一个通用的错误页面,该页面可以显示发生的错误或其他信息(自定义错误消息).当网站上发生错误时,应将用户定向到显示错误消息的页面.

例如,如果我有一个页面正在尝试将某些内容更新到数据库,但是出了点问题,我应该重定向到错误页面,该页面将包含一些自定义文本,例如"bla bla bla ...请与管理员联系."

希望这很有道理

谢谢

解决方案

在您的webconfig中,您可以指定customErrors元素:

 < system.web>< customErrors mode ="RemoteOnly" defaultRedirect ="Error.aspx"/></system.web> 

defaultRedirect应该是错误"页面的路径.这可以很好地指定何时发生一般错误,但不允许您访问堆栈跟踪.否则,您希望在gloabal.asax中的Application_Error中处理该错误,然后使用自定义消息重定向到错误页面.

im trying to implement a custom error page, what i want to be able to do is have a single generic error page which can display the error which occurred or other information (custom error message). when a error occurs on the website, the user should be directed to this page which shows the error message.

so for example if i had a page which was trying to update something to a database, but something went wrong, i should be redirected to the error page which will have some custom text like something like " there has been an error with bla bla bla ... please contact administrator".

hope this makes sense

thanks

解决方案

In your webconfig you could specify the customErrors element:

<system.web>
   <customErrors mode="RemoteOnly" defaultRedirect="Error.aspx" />
</system.web>

The defaultRedirect should be the path to your Error page. This is good to specify when general errors occur, but it won't let you access the stack trace. Otherwise you want to handle that in the gloabal.asax in the Application_Error and then redirect to the error page with the custom message.

这篇关于ASP.net自定义错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆