I got problems with ASP.NET 2.0 Themes and Url Rewriting today. I came across the fact that Url Rewriting breaks your ASP.NET 2.0 Themes by changing the base file path looked at by the client and screwing up the relative URL to your stylesheets.

When you are using themes, the ASP.NET engine will automatically create <link href="App_Themes/themename/css/yourcss.css" type="text/css" rel="stylesheet" /> tags for each css file placed in (or under) the active theme directory.

If you at the same time are using url rewriting you will probably end up with no css being found - cause the link href'' statement uses a relative path. So a request to

/www.store.com/category_12/article12.aspx

which you rewrite to

/www.store.com/article.aspx?artid=12&cat=12

will of course try to find the css at

/www.store.com/category_12/themes/css/....

instead of

/www.store.com/themes/css/....

 

The simple solution is to use the rebaseClientPath flag in RewritePath: Turns out this problem with Url Rewriting and ASP.NET 2.0 Themes was reported to Microsoft and they created a new boolean parameter for HttpContext.RewritePath, called rebaseClientPath, that allows you to specify whether or not you want the virtual path reset when doing Url Rewriting.

public void RewritePath (string path, bool rebaseClientPath)

By default, rebaseClientPath is set to true, which is why the links to the stylesheets are broken.  If you are doing Url Rewriting with ASP.NET 2.0 Themes and having problems with your stylesheets, change your code to set rebaseClientPath to false and it may fix your problem.