All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
asp.net定制简单的错误处理页面_[Asp.Net教程]

Writer: delv Article type: Programming skills(编程技巧) Time: 2014/1/10 6:27:55 Browse times: 367 Comment times: 0

asp.net定制简单的错误处理页面_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

asp.net定制简单的错误处理页面_[Asp.Net教程]

























通常web应用程序在发布后,为了给用户一个友好界面和使用体验,都会在错误发生时跳转至一个自定义的错误页面,而不是asp.net向用户暴露出来的详细的异常列表。
简单的错误处理页面可以通过web.config来设置




如果想通过编程的方式来呈现错误原因,可以通过Page_Error事件来做这件事.
另一种方式则可以通过Global.asax来实现,我觉得这种方式较为方便,另外如果能结合一个单独的更加友好的页面,则看来起更舒服一些



Global.asax(如果需要,可以记录错误日志) void Application_Error(object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string error = "发生异常页: " + Request.Url.ToString() + "
";
error += "异常信息: " + objErr.Message + "
";
Server.ClearError();
Application["error"] = error;
Response.Redirect("~/ErrorPage/ErrorPage.aspx");
}
ErrorPage.aspx




protected void Page_Load(object sender, EventArgs e)
{
ErrorMessageLabel.Text = Application["error"].ToString();
}当最终用户使用应用程序的时候,他们可能不想知道错误的原因,这个时候,我们可以通过复选框来实现,是否呈现错误的原因。可将Label放在一个div中,然后用复选框来决定是否呈现div




http://www.cnblogs.com/EasyLive2006/archive/2007/01/07/613922.html




来源:博客园

















































There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.