Oddur's asp.net url rewriting adventures, part 1 : HttpContext.RewritePath version 1.1
In our CMS System, Disill, we are using http modules for url rewriting, creating human readable url from the sitemap defined in the system. There we are using the HttpContext.RewritePath to rewrite the path to the .aspx page template. In version 1.0 of the framework the RewritePath worked fine, for 3-4 times and then started giving me a 404 error when I was calling it like this
Context.RewritePath(target.ToString());
Where target is a StringBuilder object containing the path to the real .aspx including a querystring (~/templates/frontpage.aspx?bleh=blah&foo=bar), After a while lot of debugging and pulling most of me hair out. I discovered that this function worked fine if the original request did not have an empty querystring, resulting in "?." being appended to the end of all URL paths in the system.
After I upgraded to 2003 and started compiling using version 1.1 of the framework, I saw a overload of the RewritePath that looked like this
public void RewritePath(string filePath, string pathInfo, string queryString);
The first thing a spotted there was that the filepath and the querystring are separate string, maybe this could be the thing I was looking for all the time. I rewrote my single line of code so that it looks like this:
Context.RewritePath(target.ToString(), Context.Request.PathInfo, querystring.ToString());
Tried calling the dev setup without a query string, ok, it worked, hit F5 a couple of times (where it usually would break), everything worked. Thought to myself: "this is to good to be true, I'll start the Microsoft Application Center Test and put it under some pressure". Zero errors. Finally, I'll be able to publish clean path (e.g. looking like /frontpage/subpage/blah/foo/bar instead of /frontpage/subpage/blah/bar/view.aspx?., note the view.aspx thing is a whole other subject)