giovedì 20 dicembre 2007

ResolveUrl not resolving

Since the .net conversion of SkakkiNostri, we were facing a rare and strange problem.
When the user clicks the quick Search button, it is internally redirected to a more specialized page using the line:

Response.Redirect(ResolveUrl("~/search_users.aspx?quickValue=" + txtUser.Text), true);

This line was causing 404 errors, with the ResolveUrl call apparently not doing what it has to do: the user was redirected to

Can you spot the problem?

Hint: today, while skimming through the error list I noticed something strange. All of these error reports were for users that contained unicode characters. Lots of them, like in the word "•]•·´º´·» .:. rO£@Lb@ ιи ℓσνє.:. [♡] «·´º´·•[•".

Then came the enlightenment: maybe the ResolveUrl call fails if the URL is not perfectly url-formatted!
And it turns out it's just that way. As simple as it seems, the offending call was promptly replaced with:

Response.Redirect(ResolveUrl("~/search_users.aspx?quickValue=" + Server.UrlEncode(txtUser.Text)), true);

and suddenly exceptions stopped.
Now let's go for a check of all the Response.Redirect calls in the web site :)