I have the below code in Global.asax.cs, now I get the expected ouput if I comment only the server,transfer line. Earlier I also commented the line which sets session value.
protected void Application_Error(Object sender, EventArgs e)
{
if (HttpContext.Current.Session == null)
return;
Exception exception = HttpContext.Current.Server.GetLastError().GetBaseException();
if (exception != null)
{
HttpContext.Current.Session["Error"] = exception;
HttpContext.Current.Server.Transfer("~/Error.aspx");
}
}