In error page we can get the actual exception or error information
using Server.GetLastError() method like below,
public partial class Error : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs
e)
{
Response.Write(Server.GetLastError());
}
}
Most of the time it is not advisable to show the error
information using Server.GetLastError() because the error message will be
technical which is not appropriate to the enduser.
Using Application_Error event in Global.asax
We can trap the error in Application_Error if it is not
trapped in Page_Error event. We can log the error information into a
Eventlog,etc..
void Application_Error(object sender, EventArgs e)
{
//Event log code
Server.ClearError();
}
Using Web.Config
This is most commonly used approach using configuration
settings.
<customErrors defaultRedirect="Error.aspx"
mode="On">
</customErrors>
|