ASP.NET Hosting

Boosting search engine results with URL rewriting

I don't know whether you noticed this trend that consists in masquerading URLs such as http://mysite.com/Article.aspx?id=123 so they appear like this: http://mysite.com/Articles/123.aspx

It's done here on weblogs.asp.net for example. Just look at this page's URL. ScottW and .Text do this using HTTP handlers. Another way to do this is to use the HttpContext.RewritePath method.

I decided to give it a try with the SharpToolbox. As soon as I did, the site got a boost from Google. Two days ago, Google was only linking to the main page, but now Google also returns links to tool and category pages which is much more useful. Let's say for example you're searching for an assembly decompiler, an XAML tool, or a C# object relational database mapping tool, chances are high that you find it in the SharpToolbox thanks to Google :-)

Update: Jason Salas has a post about this. Also read the comments there.

5 Comments

  • Not really related to Google but I am using handlers for a file extension hack to produce excel files from aspx. I generate a data grid and render is alone to the client as an excel app type. Problem is the client gets the file as an aspx and this is trouble if they save to disk. Solution: create a handler for xls and treat is just the same as your call to aspx; I can have querystring params and all and when they save to disk it saves as an xls file.

  • Nice use of HTTP handlers!

  • Hey Jason! I had read your post, but I wasn't able to find it back. Now I can link to it :-)

  • hello sir,

    i read your article on URL rewriting in asp.net on msdn.i have also used the same in my



    project.URL rewriting is working fine in our LAN and on our configured IP but problem is



    that when we host our site to some ISP its not working and giving error like this "THE PAGE



    CAN NOT BE FOUND" its really emberrasing because i am not able to find out the proble any



    where

    i am seding the code which i am using

    Sample code

    ==================

    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)

    ' Fires at the beginning of each request

    Dim context As HttpContext

    context = HttpContext.Current()

    Dim strOldPath As String

    strOldPath = Trim(context.Request.Path.ToLower())

    Dim strToken As String

    strToken = "accomodationdetail"

    Dim intI As Integer

    intI = strOldPath.IndexOf(strToken)

    Dim intLen As Integer

    intLen = strToken.Length

    Dim intJ As Integer

    If intI <> -1 Then

    intJ = strOldPath.IndexOf(".aspx")

    If intJ <> -1 Then

    Dim strDetail As String

    strDetail = strOldPath.Substring(intI + intLen, intJ - (intI + intLen))

    Dim strNewPath As String

    strNewPath = strOldPath.Replace(strToken + strDetail + ".aspx",



    "AccomodationDetail.aspx?intID=" & strDetail)

    context.RewritePath(strNewPath)

    End If

    End If

    end sub

    ============================



    but when i called some page like this



    original request=/accomodation/accomodationdetail22.aspx

    after rewrite=/accomodation/accomodationdetail.aspx?id=22

    above request is doing fine in our lan and on our configured IP

    but not working on ISP where we host our site

    and giving error "THE PAGE CAN NOT BE FOUND"

    i think you got my problem

    please help me as soon as possible

    thanks

    regards

    sandeep

    MY MAIL id IS spandit@rsbsystems.com

  • Sounds strange. Did you try to trace what's happening. You should probably log the values of context.Request.Path and strNewPath to get an idea about what's wrong.

Comments have been disabled for this content.