1. custom error page
Although the public error message we send to the user is secure, that is, it does not threaten the secret of the application, but such information is not good-looking. Maybe you want users to never see such information. On the contrary, if an error occurs during request processing, you want to display your "custom error page ", display your own brand and specific error information.
It is easy to add custom error messages to ASP. NET applications. First, write your own web page, which can be any type of Files:. htm,. aspx,. asp, and so on. Modify the configuration information in the config. Web file of the application to point it to the file.
For example, the following configuration information indicates that the browser should be redirected to the "errorpage. aspx" page in case of any unscheduled handling error:
You need to configure in Web. config:
<! -- Custom configuration error, not closed, open, details -->
<System. Web>
<Customerrors mode = "on" defaultredirect = "~ /Errorpage. aspx ">
<Error statuscode = '000000' redirect = '~ /Erorr500.htm '/>
<Error statuscode = '000000' redirect = '~ /Erorr403.htm '/>
<Error statuscode = '000000' redirect = '~ /Erorr404.htm '/>
<Error statuscode = '000000' redirect = '~ /Erorr505.htm '/>
</Customerrors>
</System. Web>
"On": indicates that custom error pages are always sent;
"Off": indicates that the custom error page is never sent (you always see the original error message );
"Remoteonly": indicates that a custom error page is issued only when a remote browser clicks the site (the developer clicking the site on the actual machine sees the detailed error information ).
2. Add the application error code to the Global. asax file and write it to the system log file.
Protected void application_error (Object sender, eventargs E)
{
Exception lasterror = server. getlasterror ();
String errmessage = lasterror. tostring ();
String LOGNAME = "mylog ";
String message = "url" + request. Path + "error:" + errmessage;
If (! EventLog. sourceexists (LOGNAME ))
{
EventLog. createeventsource (LOGNAME, LOGNAME );
}
EventLog log = new EventLog ();
Log. Source = LOGNAME;
Log. writeentry (message, eventlogentrytype. Information, 1 );
Log. writeentry (message, eventlogentrytype. error, 2 );
Log. writeentry (message, eventlogentrytype. Warning, 3 );
Log. writeentry (message, eventlogentrytype. successaudit, 4 );
Log. writeentry (message, eventlogentrytype. failureaudit, 5 );
}
Original post address: http://www.cnblogs.com/innhyul/archive/2010/03/26/1696947.html