Quick Error messages with Global.asax
Error pages without any effort
void Application_Error(object sender, EventArgs e)
{
Server.Transfer(
"/error.aspx"); //Displays the error page
}
In error.aspx add this to the content area.
<p>We're sorry, but the <%=Server.GetLastError().Message.ToLower() %></p>
Thats it. Easy!
Revision number 1, Wednesday, August 11, 2010 1:57:16 PM by lykasd
You must Login to comment.
|
Tue, Aug 17, 2010 6:50 PM
by gary w. smith
|
I find it a useful to create some type of static class to capture the error in the application_error section to log it and then to some type of server transfer. The method on the static class was also wrapped into a try/catch to make sure that it didn't throw an error itself.. One of the things that you must remember, which might not be too obvious here, is that you need to make sure in your application_error method that you DONT TRANSFER if the page throwing the error is also the destination page. I was called in to troubleshoot a problem where they were doing just that. The error was being thrown in their master page and the error page was derived from that. So they pretty much had an endless loop.
|
|
Thu, Aug 26, 2010 2:59 AM
by johnjalani
|
Technically you can easily do the transfer in the web.config but placing it in the Global.asax make it more easier and flexible. thnx
|
|
Thu, Nov 18, 2010 3:21 AM
by bhardwaj3055
|
This Code is for C# or VB
|