Asp.net error page

Source: Internet
Author: User

You only need to add the following code in Web. config.

 

<System. Web>
<Customerrors mode = "on" defaultredirect = "~ /Error. aspx "<! -- The recommended global mode is remoteonly: The detailed error information is displayed on the local machine, and the custom error page is displayed on other machines. -->
<Error statuscode = "404" Redirect = "~ /404.html "/>

<! -- If it is local, you can add known errors such as 404,403 -->
</Customerrors>
</System. Web>

You can write code in error. aspx to write the error information to the log file.

 

Using system;
Using system. Web;
Using system. IO;

Namespace gridview warehouse receiving ticket management
{
Public partial class error: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
Exception EX = httpcontext. Current. server. getlasterror (); // get the error object;
String line = "------------------------------------------------------------------------------";
File. appendalltext (server. mappath ("~ /Log.txt "), Ex. Message + ex. stacktrace +" \ n "+ datetime. Now +" \ n "+ line );
}
}
}

}


Format of the generated error message: (tested with 404)

 

The file does not exist. In system. Web. staticfilehandler. getfileinfo (string virtualpathwithpathinfo, string physicalpath, httpresponse response)
In system. Web. staticfilehandler. processrequestinternal (httpcontext context, string overridevirtualpath)
In system. Web. defaulthttphandler. beginprocessrequest (httpcontext context, asynccallback callback, object state)
In system. Web. httpapplication. callhandlerexecutionstep. system. Web. httpapplication. iexecutionstep. Execute ()
In system. Web. httpapplication. executestep (iexecutionstep step, Boolean & completedsynchronously)
18:19:03

------------------------------------------------------------------------------


 

 

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.