I am having some really strange behaviour in ASP.NET MVC3. Basically I've written an HttpModule that fires on BeginRequest which potentially rewrites my URL using HttpContext.RewritePath(string)
. This works properly in most cases, but I've noticed that when I have a space in my URL, ASP.NET MVC behaves differently when rewriting.
Example URL:
http://www.mysite.com/my%20url
My rewriter is set up with Regex, similar to Helicon, where it may capture a group and use that captured group in the rewrite. An example rule is:
<add original="^/(.*)\?test$" rewritten="/$1" />
This would rewrite a URL such as http://www.mysite.com/my%20url?test
to http://www.mysite.com/my%20url
<-- note that the querystring goes away. This functions correctly.
And my MVC routing is set up to capture the my%20url
part with a wildcard in order to map it to a RouteData value under the key of "navstate". The rule looks like:
"{*navstate}"
So, when I don't rewrite, my RouteDataDictionary contains:
key: "navstate" value: "my url"
When I DO rewrite, my RouteDataDictionary contains:
key: "navstate" value: "my%20url"
Note that it did not URL Decode the RouteData variable.
Does anyone have any ideas on this? The only thing that seems to make a difference is the use of HttpContext.RewritePath(string)
in my HttpModule... Turning off the module ensures proper functionality. Manually decoding the URL prior to the rewrite call using HttpUtility.UrlDecode(string)
also makes it work... but feels like a hack.
EDIT:
This seems to be a bug not with MVC, but with ASP.NET Routing, so I have updated the tags as such.