Category Archives

6 Articles

Posted by .Ronald on

URL Rewriting in IIS 7

I started to use URL Rewriting on a Windows 2008 Server running Internet Information Server 7.  At the time of writing, a technical preview of the module is available here: Using URL Rewrite Module.

After installing the module, I was able to configure a first rule that rewrote an incoming URL in the form of http://server/en/catalogue/123/abc123 to http://server/Catalogue.aspx?l=en&cat=123&sub=abc123, exactly the way I wanted it.

But when opening the page, I saw my layout and styles were gone.  Not difficult to know where the problem is, because stylesheets and images are loaded from the client with their path relative to the requested page.  In this case a reference to "style.css" will be loaded from http://server/en/catalogue/123/style.css instead of http://server/style.css, as the client doesn’t know we’re using URL rewriting on the server.

To get around this problem, several options are possible.  I’ll list few of them here, some good, some even worse.  Of course, these are not the only ones, but these were the ones I looked at to solve my problem.  Other solutions might be even better, so any input and feedback is welcome. My solution is much easier and fits my needs.  It’s posted below the other options.

  1. Override the Render() method of your base page or masterpage: URL rewriting breaks ASP.NET 2’s themes
  2. Use RewritePath Method (String, Boolean) with the second parameter (rebaseClientPath) set to false. (Huh? custom code?)
  3. Move your images and stylesheets out of the App_Themes folder (WTF?): URL Rewriting and folders with dashcommerce
  4. Hardcode your links to stylesheets and images (OMG!)
  5. I’m not going to list any more options as it’s getting worse and worse…

But why don’t you use the power when you’re using the force?

I wrote a rule that is processed before any other rule, and which takes any url pointing to file in an App_Themes folder (or just a stylesheet, which is also possible in the same way):

  • Pattern: ^(.+)/App_Themes/(.+)
  • Rewrite URL: App_Themes/{R:2}
  • and check "Stop processing of subsequent rules"

If you make sure that this rule is processed before the other regular rules by moving it to the top in the ordered list, than all references to theme files (stylesheets, images,…) are correctly served and your layout remains correct.

Posted by .Ronald on

A List Apart: Articles: Graceful E-Mail Obfuscation

Many web users don’t understand the inevitable consequences of exposing their e-mail address on the web. Experienced web developers and website owners, however do. Thousands of spam bots tirelessly crawl the web to collect e-mail addresses exposed on websites, in blog comments and elsewhere. These addresses end up in databases sold to unsavory marketers, who bombard the owners’s inboxes with unsolicited mail.
Of course, spam is an increasingly complicated problem that can never be solved by the efforts of web developers alone. But don’t underestimate your own powers.

A List Apart: Graceful E-Mail Obfuscation