When your application throw error, then 'Application_Error' event will occur in global.asax
in that you can use 'Server.GetLastError()' method to get last error occurred, here you can get 'InnerException' and redirect to error page
see below snippet
Global.asax
void Application_Error(object sender, EventArgs e)
{
Exception err = Server.GetLastError();
Session["error"] = err.InnerException.Message;
}
void Session_Start(object sender, EventArgs e)
{
Session["error"] = "";
}
<customErrors mode="On" defaultRedirect="Error.aspx"></customErrors>
protected void Page_Load(object sender, EventArgs e)
{
if (Session["error"] != null)
{
Response.Write(Session["error"].ToString());
}
}
hope it helps