asp.netquery-stringurl-encodingurlrewriter

Ampersands in URLRewriter Query Strings


I have a query string parameter value that contains an ampersand. For example, a valid value for the parameter may be:

a & b

When I generate the URL that contains the parameter, I'm using System.Web.HTTPUtility.UrlEncode() to make each element URL-friendly. It's (correctly) giving me a URL like:

http://example.com/foo?bar=a+%26b

The problem is that ASP.NET's Request object is interpreting the (encoded) ampersand as a Query String parameter delimiter, and is thus splitting my value into 2 parts (the first has "bar" as the parameter name; the second has a null name).

It appears that ASP.NET is URL-decoding the URL first and then using that when parsing the query string.

What's the best way to work around this?


UPDATE: The problem hinges on URLRewriter (a third-party plugin) and not ASP.NET itself. I've changed the title to reflect this, but I'll leave the rest of the question text as-is until I find out more about the problem.


Solution

  • Switching to UrlRewritingNet.UrlRewrite did not help, as it apparently has the same bug. I'm thinking it might have something to do with ASP.NET after all.