How to setup a common error page in ASP.NET website? Also how to handel the error in Data Access Layer by common error page?
In my current project I'm sticking with Application_Error in the global.asax for showing the end-users a uniform error page in case of any unhandled errors. I added a sendmail call to mail certain exceptions to a mail address to get a better insight in what went wrong (you can't rely on customers/visitors to properly describe the problem). After sending the mail and/or logging the problem I redirect users to a error.html with a generic errormessage.
In my DAL I try/catch most of the critical functions and show a warning/error accordingly (I return a status/message to show if for example a connection couldn't be made/timed out).
This is the pattern I tend to start with when starting a new app. Apologies this is in VB.NET ;)
In the global.asax Server.Transfer to your custom Error page.
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Server.Transfer("~/Error.aspx", False)
End Sub
Then in your custom error page.
Private Sub Page_Load
Response.Clear()
Dim err As Exception = Server.GetLastError
...
End Sub
Now you can test the Type of the exception. You'll need to recurse down through the inner exceptions as the parent exception will be probably be a general web exception. Get your DAL to throw a custom typed exception and you can test for that and handle differently.