I want to use Response.Redirect to redirect the browser when an exception occurs.
I also want to pass the exception message to my error page.
For example:
string URL = "Page2.aspx?Exception=" + ex.ToString()
Response.Redirect(URL)
Can it be done? Is this the right syntax?
Instead of
Response.Redirect, which sends a response to the client asking it to request a different page, you should callServer.Transfer, which runs a different page immediately and sends that page directly to the client.You can then put the exception in
HttpContext.Itemsand read it fromHttpContext.Itemsin your error page.For example:
In
Error.aspx, you can then get the exception like this: