My Photo

Technical Architect with over 15 years experience in a wide range of technologies.

@TheCodeKing

rss feed

SimpleUrl.Net Library | Sunday, June 22, 2008

SimpleUrl.Net is a .Net code library which allows developers to very quickly and easily implement url rewriting. This library was written to demonstrate the injection of control adapters at runtime. Read article.

For anyone looking for a rewrite solution I recommend using the Url Mapping engine from Microsoft.

Features

Unlike other rewrite libraries SimpleUrl.Net uniquely works with Ajax libraries out of the box, and also retains the standard HtmlForm rendering behaviour such as support for defaultbutton.

  • Friendly urls retained on post-back
  • Supports Ajax libraries
  • Force SSL on configured pages
  • Retains default Form behaviour such as defaultbutton
  • Supports Regular expression based url matching

Installation & Setup

To install the url rewriter follow the instructions below. Refer to the demo application included for further information.

1. Add a reference to SimpleUrl.Net.
2. Add the rewrite HttpModule to the Web.Config.
   <httpModules>
      ... 
     <add name="RewriteModule" type="CodeKing.SimpleUrl.UrlRewriter, SimpleUrl.Net" />
   </httpModules>
3. Configure the url mapping.
  <!-- disable ssl redirection for development servers -->
  <simpleUrl.Net enableSSLRedirection="false">
    <!-- direct mapping, force page to ssl -->
    <add virtualPath="/ssl/simple.aspx" url="/default.aspx" ssl="true" />
    <!-- match all aspx in virtual directory -->
    <add virtualPath="/virtual/(.+)(\.aspx)$" url="/default.aspx?path=$1" ssl="true" />
    <!-- match all aspxs -->
   <add virtualPath=".+?(.aspx)$" url="/default.aspx" />
  </simpleUrl.Net>

2 comments:

Anonymous said...

Is the source available?
Or do you have a version that handles ~ (eg: ~/images/thing.gif embedded in a page that has been urlrewritten)?

Mike Carlisle said...

Yes the library supports image rewrites, you just need to map them in the web.config.

For example:

<add virtualPath="/virtual/images/(.+)?$" url="/library/getImage.aspx?image=$1" />

Maps:
/virtual/images/test.gif
To:
/library/getImage.aspx?image=test.gif

The browser only ever sees the friendly url.

Note: If you are using IIS you will need to map a widecard filter to the .Net ISAPI, otherwise image requests will never hit the .Net framework. Email me if you would like more details.

The source isn't currently online, but I may add it to codeplex at some point in the future.

Post a Comment