asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Using the Microsoft URL Rewrite Module for IIS 7.0
By John Peterson
Rating: 4.6 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article



    An Introduction to URL Rewriting

    One of the greatest things about dynamic Web sites is the fact that you can build one page and based on the parameters that are passed to that page it can display any number of different results. For example, let's say that you're building a Web-based grocery store. Instead of creating a separate static HTML page for each category of product you carry, you can simply create a single Category.aspx file and pass it a parameter indicating what category of products you want to display:

    http://www.MyVirtualGroceryStore.com/Products/Category.aspx?Category=Fruit
    http://www.MyVirtualGroceryStore.com/Products/Category.aspx?Category=Meat
    http://www.MyVirtualGroceryStore.com/Products/Category.aspx?Category=Vegetables

    While the resulting Web pages are all generated by the single script, they'll each display a very different lists of items. This type of power is great for us as developers, but it's not so good for users and even worser if you're trying to get the pages indexed by search engines. While I created the examples above to be as user-friendly as possible, they're still not all that simple to the average user. These are simpler and much more intuitive:

    http://www.MyVirtualGroceryStore.com/Products/Fruit
    http://www.MyVirtualGroceryStore.com/Products/Meat
    http://www.MyVirtualGroceryStore.com/Products/Vegetables

    So, ever since developers started building dynamic pages and confusing users and search engines, people have been trying to find a way to get the best of both worlds. One of the most common solutions is URL rewriting. URL rewriting is where a user can request a page via the user-friendly URL:

    http://www.MyVirtualGroceryStore.com/Products/Fruit

    and the Web server figures out to actually use the the script located at:

    http://www.MyVirtualGroceryStore.com/Products/Category.aspx?Category=Fruit

    to build and return the resulting Web page.

    This concept is not a new one. Developers have been doing it for quite some time and in addition to the numerous third-party URL rewrite products available, ASP.NET actually includes some built-in support for it via URL Mapping and the HttpContext.RewritePath Method. The problem is that using them can be relatively complex and each approach comes with its own drawbacks.

    Note: Since this article's focus is on getting the IIS 7.0 Rewrite Module up and running, I'm not going to do an in-depth discussion of each of the different approaches. Scott Guthrie has an excellent post which covers the different approaches here: ScottGu's Blog: Url Rewriting with ASP.NET.

    If you're not running IIS 7.0 (or later) or you simply decide that the module discussed in this article is not appropriate for your project, in addition to Scott's Blog (and the links you can find there) you may also find the following articles useful: MSDN: URL Rewriting in ASP.NET and 15 Seconds: Rewrite.NET -- A URL Rewriting Engine for .NET

    Microsoft URL Rewrite Module for IIS 7.0

    The first step is to make sure you can use the module. You'll need to make sure you're running IIS 7.0 or later (which means Windows Server 2008 or Vista). You'll also need interactive access to the server to run the install routine. If you meet the above requirements, you can download the version of the module that matches your server's platform from the IIS 7.0 Web site:

    It's a relatively small download and shouldn't take you very long to get. The installation is quick and doesn't offer any configuration options.

    Microsoft URL Rewrite Module for IIS 7.0 Setup - License Agreement

    Microsoft URL Rewrite Module for IIS 7.0 Setup - Please Wait

    Microsoft URL Rewrite Module for IIS 7.0 Setup - Complete

    One the module is installed, if you run "Internet Information Services (IIS) Manager", go to your Web site, and look in the "Features View", you should now see an icon labeled "URL Rewrite".

    URL Rewrite Icon in IIS Manager

    Clicking the icon will bring you to the URL Rewrite configuration area.

    URL Rewrite Section in IIS Manager

    To create a rule click on the "Add Rules..." link in the "Actions" pane on the right. That will bring up the following dialog box from which you can select a rule template.

    URL Rewrite "Add Rule" Dialog Box

    Selecting the "Blank Rule" template will let you build your own rule by hand, but since we're building a rule to define user-friendly URLs, let's use the "User friendly URL" template. The template asks for a sample of the actual URL our application is using so I'll give it our example from earlier: http://www.MyVirtualGroceryStore.com/Products/Category.aspx?Category=Fruit. From that it offers some suggestions for what you might want the user-friendly URL to be.

    URL Rewrite "User friendly URL" template

    None of the choices fit exactly, but the third one is close to what I want so I'll choose that one and simply remove the "Category" part from the "URL pattern" box:

    URL Rewrite "User friendly URL" template - Modified

    Clicking the "OK" button will add the rule and I never even had to brush up on my regular expression syntax.

    A Quick Look from a Client-Side Browser

    Okay so what did we just accomplish? Let me show you. I set up a very simple page that just writes back out what it receives via the QueryString to illustrate how things work. Before adding our URL rewriting rule, I can access the page via the real URL:

    URL Rewrite In Action - Real URL

    But, using the user-friendly URL results in a familiar error message:

    URL Rewrite In Action - Friendly URL Before

    After adding the rule discussed above, visiting the same user-friendly URL loads the correct page and the visitor never even knows that the "/Products/Fruit" folder doesn't exist and that the page was actually generated by the "Category.aspx" script.

    URL Rewrite In Action - Friendly URL After

    Conclusion

    I hope this article has shown you just how easy it is to implement URL rewriting by using the Microsoft URL Rewrite Module for IIS 7.0. While the module is extremely powerful and robust, it's also quite easy to install and use. While some of the more advanced features may take some time to become familiar with, even a novice developer should be able to get the basics up and running in just a few minutes.

    For a more in-depth coverage of the IIS 7.0 URL Rewrite Module, take a look at the excellent documentation available here: IIS.NET: Microsoft URL Rewrite Module for IIS 7.0 (x86) Documentation.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Jul 21, 2005 - N-Tier Web Applications using ASP.NET 2.0 and SQL Server 2005 - Part 1
    While the .NET Framework made building ASP.NET applications easier then it had ever been in the past, .NET 2.0 builds on that foundation in order to take things to the next level. This article shows you to how to construct an N-Tier ASP.NET 2.0 Web application by leveraging the new features of ASP.NET 2.0 and SQL Server 2005.
    [Read This Article]  [Top]
    Apr 28, 2005 - New Files and Folders in ASP.NET 2.0
    With the release of ASP.NET 2.0, Microsoft has greatly increased the power of ASP.NET by introducing a suite of new features and functionalities. As part of this release, ASP.NET 2.0 also comes with a host of new special files and folders that are meant to be used to implement a specific functionality. This article examines these new files and folders in detail and provides examples that demonstrate how to utilize them to create ASP.NET 2.0 applications.
    [Read This Article]  [Top]
    Mar 10, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 2, Cont'd
    Alex Homer continues his detailed look at the major changes to the DataSet class. In this part, he looks at two features that allow developers to work with data in a more structured and efficient way when using the DataSet with a SQL Server 2005 database server.
    [Read This Article]  [Top]
    Mar 9, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 2
    Alex Homer continues his detailed look at the major changes to the DataSet class. In this part, he looks at two features that allow developers to work with data in a more structured and efficient way when using the DataSet with a SQL Server 2005 database server.
    [Read This Article]  [Top]
    Mar 3, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 1, Cont'd
    In this article, Alex Homer looks at the changes between the version 1.x and version 2.0 DataSet and their associated classes, showing you how you can take advantage of the new features to improve your applications' capabilities and performance.
    [Read This Article]  [Top]
    Mar 2, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 1
    In this article, Alex Homer looks at the changes between the version 1.x and version 2.0 DataSet and their associated classes, showing you how you can take advantage of the new features to improve your applications' capabilities and performance.
    [Read This Article]  [Top]
    Feb 16, 2005 - Writing a Custom Membership Provider for the Login Control in ASP.NET 2.0
    In ASP.NET 2.0 and Visual Studio 2005, you can quickly program custom authentication pages with the provided Membership Login controls. In this article, Dina Fleet Berry examines the steps involved in using the Login control with a custom SQL Server membership database.
    [Read This Article]  [Top]
    Dec 29, 2004 - ClickOnce Deployment in .NET Framework 2.0
    In this article, Thiru Thangarathinam examines .NET 2.0's new ClickOnce deployment technology that is designed to ease deployment of Windows forms applications. This new technology not only provides an easy application installation mechanism, it also eases deployment of upgrades to existing applications.
    [Read This Article]  [Top]
    Dec 15, 2004 - A Sneak Peek at ASP.NET 2.0's Administrative Tools
    With ASP.NET 2.0, Microsoft has made great strides in increasing developer productivity and has made implementing previously complex solutions relatively easy. Where this version of ASP.NET really shines, however, is in its new administrative tools that allow developers to spend less time managing the configuration of the servers and software and more time developing great code.
    [Read This Article]  [Top]
    Nov 17, 2004 - The ASP.NET 2.0 TreeView Control
    Thiru Thangarathinam introduces ASP.NET 2.0's new TreeView control which provides a seamless way to consume and display information from hierarchical data sources. The article discusses this new control in depth and explains how to use this feature rich control in your ASP.NET applications.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry

    internet.commediabistro.comJusttechjobs.comGraphics.com

    Search:

    WebMediaBrands Corporate Info

    Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
    Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs