I have an asp.net application and I am trying to handle custom exception using Application_Error. It works nicely but I have new requirement to set the error data in Session obj
Add a directive to the Global.asax file, Imports the System.Web Namespace
<%@ Import Namespace="System.Web" %>
void Application_Error(object sender, EventArgs e) {
string message = Server.GetLastError().Message;
Session["error"] = message;
Server.Transfer("Error.aspx");
}
Write the error message added in the sesion object in the Error.aspx page
protected void Page_Load(object sender, EventArgs e){
if (!this.IsPostBack)
Response.Write(Session["error"].ToString());
}