iSkool.Net
Remember me 
[ Forgotten Password? ] [ Sign up ]
Blogs
jack
Blog Titles
Custom paging a datalist .Net 2.0 +
[ 5/5/2009 5:26:04 AM ]
Handling extensionless URLs
[ 6/24/2007 12:55:05 AM ]
Screen Shot Grabber
[ 3/3/2007 9:59:51 PM ]
Handling extensionless URLs


In one web project I wanted to give the newly created user their own individual URL in the form of http://www.MySite.com/ TheirName

The problem with this is that the word TheirName is extensionless and IIS will throw a 404 error "Page not Found"

By extensionless, I mean there is no page extension such as html or aspx.
http://www.MySite.com/ TheirName.aspx will always be served by IIS
but it is not what I wanted

Looking at URL re-writing and http modules - I could write a module to parse this request but found a much easier solution.

Here it is...

By default IIS will not serve an extensionless URL. However you can change that by opening IIS, right clicking your website and choosing properties and then the custom errors tab.
Scroll down to the 404 and double click it. Now change  the values to these settings where the URL is the path to your 404.aspx page at your site.

* Here shows only the path to the 404.aspx on the development machine.

 

Now as long as you have page called 404.aspx in your site you can now handle all extensionless URL's by using this code in the Global.asax

  Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
      
        Dim sRequestedURL As String = HttpContext.Current.Request.Url.AbsolutePath
       
        If (sRequestedURL.Contains("404.aspx")) Then
           
            Dim sRaw As String = Request.RawUrl
            Dim strFile As String = Right(sRaw, sRaw.Length - InStrRev(sRaw, "/"))
           
            Context.RewritePath("~/default.aspx?" & strFile & "", False)
           
        Else
            'do nothing /continue...
        End If
      
    End Sub



Cool.....


Rate this blog: 
Current rating:
20
     Please login to rate this blog

comments 

Comments: No comments yet



Please login to make a comment