Making IIS 6.0 Play With UrlRewriting

One topic that comes up often in SitePoint’s .NET Forum is “How do I make rewrite Urls in .NET?” The answer to this question is relatively simple, once you get into the ASP.NET pipeline. Unfortunately, given the current versions of IIS, getting to that pipeline is alot trickier than it should be. IIS really prefers to deal with known extensions rather than fancy mappings. Documentation for getting around this limitation is sparse at best.

Getting IIS Mapping Things it Does Not Want To Map

First and foremost among IIS 7’s new features is the ability to inject HttpHandlers and HttpModules on any request coming to the server. There is a reason this is the headliner—getting IIS 6 to correctly map rewritten urls is a trick in and of itself. IIS 6.0 and earlier really, really want to just take the extension from the request and map it to the proper handler for processing. So, if you wish to make your urls something like http://www.example.com/products/fluffy-bunny-slippers/ you are going to have to do a bit of engineering. Options include:

  1. Let IIS do what IIS wants to do.

    There are times when it is best to kowtow to how the underlying technology wants to work. So just change your pages to feel like pages rather than folders—such as http://www.example.com/products/fluffy-bunny-slippers.aspx. The url is nearly as hackable as the previous example while needing considerably less engineering. Your application will require no reconfiguration on the IIS level to get things mapping correctly. This tactic will also work in shared hosting scenarios where you don’t have the ability to make significant configuration changes in IIS.
  2. Use an ISAPI Module or Filter

    ISAPI modules and filters sit within IIS and handle requests before they hit ASP.NET’s pipeline. The two options are the rather cheap IISRewrite and the free ISAPI Rewrite Filter. Both use a grammar generally reminiscent, but not identical to, of mod_rewrite. This is probably the cleanest solution, but it also requires a hosting situation that lets one make significant configuration changes to IIS.
  3. Use a Wildcard mapping.

    IIS 6.0 supports wildcard mappings, where all requests to a given website are mapped to a given handler. While this sounds like a silver bullet, it has a lot of downsides. Probably the biggest one is that requests for static resources are going to be patched through the ASP.NET pipeline. Moreover, if you are using any estoric content types, you will have to make sure they are assigned a proper handler in your application or in the server’s web.config.
  4. Use a custom ASP.NET 404 page.

    If your 404 page is an ASP.NET page, then it will run the entire rendering pipeline, including calling your custom HttpModules. So, any non-existent file will still let your program get a few words in. While comparatively rather ghetto, this is a valid tactic for situations where one cannot modify significant bits of IIS nor just use .aspx urls. Unfortunately, most shared hosts will not let one use options two or three above, so this lowest common denominator is quite often used in applications today.

Now that we have the hard part—getting IIS to feed requests to ASP.NET—taken care of, we can get to the business of actually rewriting URLs. Fortunately, this is relatively easy and markedly more sane than the above. Rather than repeat the wisdom of the interwebs, I shall give you some key links:

  1. Scott Guthrie’s excellent post on Url Rewriting in .NET. Pay special attention to the last few points; they cover a few of the big gotchas in .NET url rewriting.
  2. UrlRewritingNet.UrlRewrite is a rather good .NET 2.0 library for handling the mechanics of your url rewriting needs.
  3. UrlRewriter.Net is another rather good, open source .NET 1.1/2.0 library for handling the mechanics of your url rewriting needs.
  4. Scott Watermasysk, the man who brought you .TEXT and Community Server, posts this very helpful post on a rather significant bug in .NET’s native url rewriting.
  5. The MSDN documentation for HttpContext.RewritePath, the “key” method in this endeavor.

So, take control of IIS and get to making them urls more human friendly!

Replay

Category: asp.net Time: 2007-08-22 Views: 0
Tags:

Related post

  • Playing with this SoC 2014-09-11

    I have done a few projects on Arduinos. Now I want to step up my embedded skills. I have found this SoC with embedded Linux and video encoding/decoding capabilities. I am interested on running OpenCV on it. My question is how do I play around with so

  • Where can I interactively play with jQuery and Javascript? 2010-07-20

    I know there was website I once saw that permitted me to interactively play with Javascript and JQuery. It had an IDE, a render pane and a result debugger thing too. Does anyone know what it was called or anything like this? --------------Solutions--

  • how to disable Play with Windows Media Player contextual menu? 2010-08-21

    in Windows (Vista), when viewing a folder, when right clicking on a item, there's the menu "Play with Windows Media Player". How to set it so such submenu does not show? (not sure I want to uninstall Windows Media Player though) I have no proble

  • Playing with a shift register and some LEDs 2011-03-15

    Building on this question, I've now got a shift register to play with, and I've been trying to work it manually with a couple of switches, like so: I have resistors (2.2K) between the switches and VCC, even though that's not shown in the schematic. I

  • Playing with default subnet mask: understanding the consequences 2011-05-16

    I'm playing with my router configuration, and I want to understand what happens from changing the default subnet mask from 255.255.255.0 to 255.255.0.0 is expected to do More details, I had Router IP Address: 192.168.0.1 default subnet gateway: 255.2

  • Playing with/editing partition table 2011-06-13

    While playing with GParted my partition table was damaged in the sense that an extended partition ended after the end of disk. To fix it I used TestDisk to backup the current partition table and removed the partition losing quite a lot of data. When

  • How to prevent people from playing with your website? 2011-07-24

    I have designed my first website recently. I created my own blog like thing in PHP. I write articles and below the articles there is a place to add comments. Sometimes I get random comments something like 'sd$^&(87&(*2d10hsdasko' with no meaning.

  • Can I stream any video played with VLC player to Apple TV? 2011-08-28

    Can I stream any video played with VLC player to Apple TV ? Any additional plug-in for it...? --------------Solutions------------- It's not using VLC (although it uses some of its components and should be able to open anything VLC can open), but it l

  • Gimp play with scale without losing quality 2012-02-20

    In photoshop when I transform an image(layer) and make it smaller, then decide later that I want it bigger no quality is lost, however in gimp when I resize an image(layer) and make it smaller it loses the resolution it used to have so if I resize an

  • What is the interrest of playing with drop_caches? 2012-02-21

    I've seen sysadmins playing with /proc/sys/vm/drop_caches (echo 3 into this file from a cron) in order to free caches. Is there a real interrest in doing this? Aren't the clean caches reclaimed when needed? Thanks. --------------Solutions------------

  • Playing with Fire: Organic CSS3 Animation 2012-02-22

    Mythbusters testing the chinese water torture in 2008. A few years back, I saw a great episode of Mythbusters, where they tested the idea of the Chinese water torture. One by one, Adam, Kari, Scotty and Tory were each firmly secured before being subj

  • What do I need if I want to play with 2 VM Win Servers? 2012-03-14

    Im new in the server world. I would like to make 2 virtual servers so I can play with them. What do I need? I have here a Win 7 system. Is it enough to install on this Win 7 system the free VMware Player and Install 2 Win 2008 Server as VM? If I woul

  • Is making a D flip flop with asynchronous level triggered reset possible? 2012-03-19

    I am starting to learn verilog coding in college and didn't have that much of a problem till now. I think I have the basics down perfectly. But I just hit a brick wall with this one. I was experimenting with behavioral modeling and ended up having th

  • Replicate main MySql db to a development server to play with real data 2012-04-18

    I have a main architecture with a MySql db, replication and backup, it's working fine. Now I also have a development server where I play with the code and I would like to use the data from the main db to play too, with reads and writes. How can I set

  • Making a stand-alone image with gastex 2012-06-10

    I want to do the following: Make an image using gastex. Compile the image to a stand-alone pdf image. I.e., at the end of this stage I'll have a myImage.pdf file. Include my image in a large latex file. The idea is that I like working with gastex but

  • Design Tips on making a battery powered inverter with 5A output 2012-06-27

    I'd like to make an inverter that can take an input DC voltage of 13~16V and give an output of 120VAC at 60Hz that is capable of providing up to 5A (perhaps more). For the battery, I would be using two 7.4V NiMH battery packs in series that are 4000m

  • How to play with Facebook data inside Mathematica? 2012-10-06

    I saw this post from Wolfram here and I would like to know how to import facebook data into Mathematica. --------------Solutions------------- I have made some time ago a Mathematica code to play with my Facebook graph. The code extracts your Facebook

  • I was playing with grub a bit- a bit more 2012-12-15

    I was playing with grub on my computer a bit more. Then I tried to reboot and I can't enter my operating systems (windows and Ubuntu). It looks like I've rewritten something very important because it only shows me grub command line and I don't know h

  • playing with head in ubuntu 2013-02-02

    Hi while I am playing with Ubuntu head command of CLI, I came to a situation.There what ever I am giving as input thats echoing automatically. The command and its play mentioned in the image. so could somebody explain me whats happening in there ? .

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 1.442 (s). 13 q(s)