Customizing the exception page in asp.net

Source: Internet
Author: User
Tags exception handling
Asp.net| pages are sorted by exception-handling precedence
(0) Add code to the Global.asax Application_Error
protected void Application_Error (Object sender, EventArgs e)
{
Context.clearerror ();
Response.Write ("Error");
Response.Redirect ("errorpage.htm");
}
(1) webform1_error in the background code
Add exception handling code in Ui.page Error event in properties of ASPX page
private void Webform1_error (object sender, System.EventArgs e)
{
Exception Ex=server.getlasterror ();
session["Error"]=ex. message;
Server.ClearError ();
Response.Redirect ("error.aspx");
}
(2) Add ErrorPage to HTML code
Errorpage= "Http://www.21cn.com"
(3) Add exception handling page in Web.config
<customerrors mode= "on" defaultredirect= "error.aspx" >
<error statuscode= "401" redirect= "error.aspx"/>
<error statuscode= "404" redirect= "http://www.sina.com.cn"/>
</customErrors>
(4) Setting the Exception handling page in IIS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.