Friday, January 09, 2009

Error in Asp.Net : "Redirect URI cannot contain newline characters"

While you send the error message as query string to an error page using response.redirect method in asp.net, you may come across the following error.
To get through, you should use URLEncode and URLDecode alone or with combination of HTMLEncode and HTMLDecode.

Eg:-
Response.Redirect(@"~/errorpage.aspx?.err=" + Server.UrlEncode(exception.Message) + "&.src=" + Server.UrlEncode(exception.Source));

2 comments:

nishtha said...

Hi,
ur solution works fine if same web page..bt what if i wan to have a class method to redirect to a errorpage in case of exception..
first error--Server.urlencode
it won't identify server control n i have to pass httpserverutility object..
is that the only feasible way..
can u suggest sumthng else..

dotNetSoldier said...

Nishitha-

It will work well in a class object as well. I used to have that routine in my all codings.
You can get the encode and decode using the proper System namespaces within the reusable class.

Let me know if you have further questions.