views:

83

answers:

1

So in the Global.asax is this:

protected void Application_Error(object sender, System.EventArgs { Session["CustomError"] = Server.GetLastError(); Server.ClearError(); Response.Redirect("~/ErrorPage.aspx"); }

And in ErrorPage.aspx is this:

private void Page_Load(object sender, System.EventArgs e) { Exception currentException = ((Exception)Session["CustomError"]).InnerException;

// Writes the error message if (currentException != null) txtErrorMessage.Text = currentException.Message;

// Loops through the inner exceptions. currentException = (Exception)Session["CustomError"]; while (currentException != null) { message.Append(currentException.Message).Append("\r\n").Append(currentException.StackTrace); message.Append("\n==============================================\n"); currentException = currentException.InnerException; }

As this is old 1.0 code it barfs when converted to a 3.5 Global.asax file. It tells me that "Session" is not available and also that I can't redirect?? I think one of the issues may be that there is also an error being thrown from Application_Start. But if I comment out all the application start code I still get errors but they never get redirected to the error page.

A: 

This link might help: Exceptional Gotchas!. In addition, use the web.config file to define your default redirect page for errors.

TheObjectGuy