Errorhandling with response.redirect

  • Thread starter Thread starter Roel
  • Start date Start date
R

Roel

Hello

When I have an exception within a try - catch block, I sent the user to my
error page with the following code:
Response.Redirect(@"error.aspx?errmsg=" + ex.Message + "&errsource=" +
ex.Source + "&errstack=" + ex.StackTrace);

The problem is that when there is an \n - sign in the error message or
stacktrace, I get the error "Redirect URI cannot contain newline characters"

Is there anybody who knows how I can transform the "ex.Message" into a
@string or is there another way to solve this problem

Regards
Roel
 
There are probably newlines in pretty much all of the variables you are
getting. You can try calling Server.UrlEncode.

However, keep in mind that there are also length limits on how many
characters can be passed in the query string.
 
It seems like that querystring could be huge, especially with the stacktrace
in there.

Perhaps it might be an idea to investigate passing information to your error
page via session settings, or perhaps even storing the information in a
database on the server.
 
Back
Top