asp.net自定义错误页面
2010-01-21 10:07
567 查看
web.config
Global.asax
ApplicationErroy.aspx
<customErrors mode="On" defaultRedirect="ApplicationErroy.aspx" > <error statusCode="403" redirect="403.htm"/> <error statusCode="404" redirect="404.htm"/> <error statusCode="500" redirect="500.htm"/> </customErrors>
Global.asax
<%@ Application Language="C#" %> <mce:script runat="server"><!-- void Application_Start(object sender, EventArgs e) { // 在应用程序启动时运行的代码 } void Application_End(object sender, EventArgs e) { // 在应用程序关闭时运行的代码 } void Application_Error(object sender, EventArgs e) { // 在出现未处理的错误时运行的代码 Exception erroy = Server.GetLastError(); string err = "出错页面是:" + Request.Url.ToString() + "</br>"; err += "异常信息:" + erroy.Message + "</br>"; err += "Source:" + erroy.Source + "</br>"; err += "StackTrace:" + erroy.StackTrace + "</br>"; //清除前一个异常 Server.ClearError(); //此处理用Session["ProError"]出错。所以用 Application["ProError"] Application["erroy"] = err; //此处不是page中,不能用Response.Redirect("../frmSysError.aspx"); System.Web.HttpContext.Current.Response.Redirect(HttpContext.Current.Request.ApplicationPath + "/ApplicationErroy.aspx"); } void Session_Start(object sender, EventArgs e) { // 在新会话启动时运行的代码 } void Session_End(object sender, EventArgs e) { // 在会话结束时运行的代码。 // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为 // InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer // 或 SQLServer,则不会引发该事件。 } // --></mce:script>
ApplicationErroy.aspx
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class ApplicationErroy : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //显示程序中的错误码 if (!IsPostBack) { //显示程序中的错误码 if (Application["erroy"] != null) { Response.Write(Application["erroy"].ToString()); } } } }
相关文章推荐
- 新西兰程序员 ASP.NET网站中设置404自定义错误页面
- asp.net 自定义错误页面 问题
- asp.net中创建自定义的错误处理页面
- asp.net自定义错误处理页面的几种方法
- 在ASP.NET MVC 如何在Response.StatusCode = 404的同时,显示友好的自定义错误页面
- 在ASP.NET Core中显示自定义的错误页面
- Asp.net MVC 自定义错误页面以及return HttpNotFound遇到的问题
- ASP.NET自定义错误处理页面的添加
- ASP.NET自定义错误页面(转)
- ASP.NET自定义错误处理页面的添加
- ASP.NET Core中显示自定义错误页面
- asp.net mvc输出自定义404等错误页面,非302跳转
- ASP.NET网站中设置404自定义错误页面
- 解决 ASP.NET Core 自定义错误页面对 Middleware 异常无效的问题
- Asp.Net自定义错误页面
- ASP.NET自定义错误页面,分离配置信息,多环境发布
- ASP.NET自定义错误页面
- ASP.NET 记录页面错误及自定义错误页
- Asp.Net自定义错误页面
- asp.net中自定义错误处理页面