<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://v900u039rux.maximumasp.com/Web/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Raheel Hussain : Global.asax</title><link>http://v900u039rux.maximumasp.com/Web/blogs/raheel/archive/tags/Global_2E00_asax/default.aspx</link><description>Tags: Global.asax</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP2 (Build: 20611.960)</generator><item><title>URL Rewriting (Part 3)</title><link>http://v900u039rux.maximumasp.com/Web/blogs/raheel/archive/2007/10/03/url-rewriting-part-3.aspx</link><pubDate>Wed, 03 Oct 2007 08:13:00 GMT</pubDate><guid isPermaLink="false">3790bee0-d05b-4b84-a272-3ed522a0473a:72</guid><dc:creator>Raheel Hussain</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://v900u039rux.maximumasp.com/Web/blogs/raheel/rsscomments.aspx?PostID=72</wfw:commentRss><comments>http://v900u039rux.maximumasp.com/Web/blogs/raheel/archive/2007/10/03/url-rewriting-part-3.aspx#comments</comments><description>&lt;p&gt;This is offcourse linked to the last blog for URL Rewritting, some technical bits to be shared,&amp;nbsp;a little enhancement to the previous technique to URL Rewriting and also an issue which could be a limitation (or more likely that a I&amp;#39;m unable to findout solution to it) for the way I implemented the URL Rewritting.&lt;br /&gt;&lt;br /&gt;I had implemented the URLs with a directory structure strategy.&lt;br /&gt;i.e.&amp;nbsp; &lt;a href="http://localhost:3648/Teams/"&gt;http://localhost:3648/Teams/&lt;/a&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href="http://localhost:3648/Teams/Pakistan/"&gt;http://localhost:3648/Teams/Pakistan/&lt;/a&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href="http://localhost:3648/Teams/India/"&gt;http://localhost:3648/Teams/India/&lt;/a&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href="http://localhost:3648/Teams/Sri-Lanka/"&gt;http://localhost:3648/Teams/Sri-Lanka/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;While going into live environment, I faced an issue and which (so far) I&amp;#39;m unable to resolve...&lt;br /&gt;&lt;br /&gt;The issue was that when the page was redirected to a URL (say &lt;a href="http://localhost:3648/Teams/Pakistan/"&gt;http://localhost:3648/Teams/Pakistan/&lt;/a&gt;)&amp;nbsp; the images to be displayed in the page took the different relative path for the image URL and hence not displaying the picture.&lt;br /&gt;&lt;br /&gt;For example: &lt;br /&gt;If the image path was &amp;quot;images/testimage.jpg&amp;quot; then after URL Rewritting, it became as &amp;quot;Pakistan/images/testimage.jpg&amp;quot; and therefore misguiding the browser to retreive the image from a non-existent and wrong directory...&lt;br /&gt;&lt;br /&gt;This led me to change my strategy towards URL Rewritting technique, and I rather switched to a slighly different URL Rewritting bit.&lt;br /&gt;&lt;br /&gt;i.e.&amp;nbsp; &lt;a href="http://localhost:3648/Teams.aspx"&gt;http://localhost:3648/Teams.aspx&lt;/a&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href="http://localhost:3648/Pakistan.aspx"&gt;http://localhost:3648/Pakistan.aspx&lt;/a&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href="http://localhost:3648/India.aspx"&gt;http://localhost:3648/India.aspx&lt;/a&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href="http://localhost:3648/Sri-Lanka.aspx"&gt;http://localhost:3648/Sri-Lanka.aspx&lt;/a&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href="http://localhost:3648/Hockey.htm"&gt;http://localhost:3648/Hockey.htm&lt;/a&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href="http://localhost:3648/Tennis.shtml"&gt;http://localhost:3648/Tennis.shtml&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;From the SEO (Search Engine Optimization) point of view, this is still very useful URL.&lt;br /&gt;&lt;br /&gt;I had to do the following change in the &amp;quot;&lt;font size="2"&gt;Application_BeginRequest&amp;quot;&amp;nbsp;event&amp;nbsp;in &lt;/font&gt;global.asax file&lt;br /&gt;&lt;br /&gt;Old Code:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:1px solid;BORDER-TOP:1px solid;OVERFLOW:scroll;BORDER-LEFT:1px solid;WIDTH:546px;BORDER-BOTTOM:1px solid;BACKGROUND-COLOR:#f5f5f5;"&gt;&lt;pre&gt;    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        Dim strPath As String = Request.Url.ToString()
        If strPath.Contains(&amp;quot;Pakistan/&amp;quot;) Then
            Context.RewritePath(&amp;quot;~/teampage.aspx?TeamID=1&amp;quot;)
        ElseIf strPath.Contains(&amp;quot;India/&amp;quot;) Then
            Context.RewritePath(&amp;quot;~/teampage.aspx?TeamID=2&amp;quot;)
        ElseIf strPath.Contains(&amp;quot;Sri-Lanka/&amp;quot;) Then
            Context.RewritePath(&amp;quot;~/teampage.aspx?TeamID=3&amp;quot;)
        ElseIf strPath.Contains(&amp;quot;Cricket/&amp;quot;) Then
            Context.RewritePath(&amp;quot;~/sportspage.aspx?SportID=1&amp;quot;)
        ElseIf strPath.Contains(&amp;quot;Football/&amp;quot;) Then
            Context.RewritePath(&amp;quot;~/sportspage.aspx?SportID=2&amp;quot;)
        ElseIf strPath.Contains(&amp;quot;Tennis/&amp;quot;) Then
            Context.RewritePath(&amp;quot;~/sportspage.aspx?SportID=3&amp;quot;)
        ElseIf strPath.Contains(&amp;quot;Hockey/&amp;quot;) Then
            Context.RewritePath(&amp;quot;~/sportspage.aspx?SportID=4&amp;quot;)
        Else
            Context.RewritePath(&amp;quot;~/default.aspx&amp;quot;)
        End If
    End Sub
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;New Code:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;div style="BORDER-RIGHT:1px solid;BORDER-TOP:1px solid;OVERFLOW:scroll;BORDER-LEFT:1px solid;WIDTH:546px;BORDER-BOTTOM:1px solid;BACKGROUND-COLOR:#f5f5f5;"&gt;&lt;pre&gt;    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        Dim strPath As String = Request.Url.ToString()
        If strPath.Contains(&amp;quot;Pakistan.aspx&amp;quot;) Then
            Context.RewritePath(&amp;quot;~/teampage.aspx?TeamID=1&amp;quot;)
        ElseIf strPath.Contains(&amp;quot;India.aspx&amp;quot;) Then
            Context.RewritePath(&amp;quot;~/teampage.aspx?TeamID=2&amp;quot;)
        ElseIf strPath.Contains(&amp;quot;Sri-Lanka.aspx&amp;quot;) Then
            Context.RewritePath(&amp;quot;~/teampage.aspx?TeamID=3&amp;quot;)
        ElseIf strPath.Contains(&amp;quot;Cricket.aspx&amp;quot;) Then
            Context.RewritePath(&amp;quot;~/sportspage.aspx?SportID=1&amp;quot;)
        ElseIf strPath.Contains(&amp;quot;Football.aspx&amp;quot;) Then
            Context.RewritePath(&amp;quot;~/sportspage.aspx?SportID=2&amp;quot;)
        ElseIf strPath.Contains(&amp;quot;Tennis.shtml&amp;quot;) Then
            Context.RewritePath(&amp;quot;~/sportspage.aspx?SportID=3&amp;quot;)
        ElseIf strPath.Contains(&amp;quot;Hockey.htm&amp;quot;) Then
            Context.RewritePath(&amp;quot;~/sportspage.aspx?SportID=4&amp;quot;)
        End If
    End Sub
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Also, with the changes in the URLs i.e. Hockey.htm or India.aspx, you may also had noticed that I&amp;#39;ve removed the else condition, that was because, while when the browser is reading the image file, this function is called and&amp;nbsp;the control directly goes to the else condition, while reading the image, and that lead the image URL to parse as default.aspx&lt;br /&gt;&lt;br /&gt;&amp;nbsp;Following is the&amp;nbsp;snapshot of the&amp;nbsp;application with the folder technique&lt;/p&gt;
&lt;div style="OVERFLOW:scroll;WIDTH:546px;"&gt;&lt;a href="http://yukonizer.com/Web/blogs/raheel/url_test_1.jpg"&gt;&lt;img src="http://yukonizer.com/Web/blogs/raheel/url_test_1.jpg" border="0" alt="" /&gt;&lt;/a&gt; &lt;/div&gt;
&lt;p&gt;Following is the new snapshot of the application with the URL (without folder)&lt;/p&gt;
&lt;div style="OVERFLOW:scroll;WIDTH:546px;"&gt;&lt;a href="http://yukonizer.com/Web/blogs/raheel/url_test_w_url.gif"&gt;&lt;img src="http://yukonizer.com/Web/blogs/raheel/url_test_w_url.gif" border="0" alt="" /&gt;&lt;/a&gt; &lt;/div&gt;
&lt;p&gt;&lt;br /&gt;With this strategy also, the limitations remain the same as discussed in previous post. &lt;br /&gt;But as far as SEO is concerned this way or the previous one, we can acheive our targets.&lt;br /&gt;&lt;br /&gt;The Server.Execute or Server.Transfer methods for instance, can be utilized at places where necessary but they would definetely show up with the original URL which was masked (re-written) but since the Top Level Menus of the website are using &amp;quot;response.redirect&amp;quot; method, it will still serve the purpose.&lt;br /&gt;&lt;br /&gt;The project is the same consists of the following files&lt;br /&gt;&lt;br /&gt;Global.asax&lt;br /&gt;MasterPage.master&lt;br /&gt;default.aspx&lt;br /&gt;teampage.aspx&amp;nbsp;&lt;br /&gt;sportspage.aspx&lt;br /&gt;web.config&lt;br /&gt;&lt;br /&gt;The master page contains the menus (Four link buttons) each of which redirects to a different page (A dummy URL).&lt;br /&gt;&lt;br /&gt;OLD Example Code: &lt;/p&gt;
&lt;div style="BORDER-RIGHT:1px solid;BORDER-TOP:1px solid;OVERFLOW:scroll;BORDER-LEFT:1px solid;WIDTH:546px;BORDER-BOTTOM:1px solid;BACKGROUND-COLOR:#f5f5f5;"&gt;&lt;pre&gt;    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Response.Redirect(&amp;quot;~/Cricket/&amp;quot;)
    End Sub

    Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton2.Click
        Response.Redirect(&amp;quot;~/Football/&amp;quot;)
    End Sub

    Protected Sub LinkButton3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton3.Click
        Response.Redirect(&amp;quot;~/Tennis/&amp;quot;)
    End Sub

    Protected Sub LinkButton4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton4.Click
        Response.Redirect(&amp;quot;~/Hockey/&amp;quot;)
    End Sub
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;New Example Code:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:1px solid;BORDER-TOP:1px solid;OVERFLOW:scroll;BORDER-LEFT:1px solid;WIDTH:546px;BORDER-BOTTOM:1px solid;BACKGROUND-COLOR:#f5f5f5;"&gt;&lt;pre&gt;    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Response.Redirect(&amp;quot;~/Cricket.aspx&amp;quot;)
    End Sub

    Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton2.Click
        Response.Redirect(&amp;quot;~/Football.aspx&amp;quot;)
    End Sub

    Protected Sub LinkButton3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton3.Click
        Response.Redirect(&amp;quot;~/Tennis.shtml&amp;quot;)
    End Sub

    Protected Sub LinkButton4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton4.Click
        Response.Redirect(&amp;quot;~/Hockey.htm&amp;quot;)
    End Sub
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;------------------------&lt;br /&gt;&lt;br /&gt;Although, this is one other way for implementing the URL re-writting, I&amp;#39;ll will welcome to some one of you would find a solve to it to help me out &lt;br /&gt;as well as I will be searching for it, and will update you if I find some resolution to that.&lt;br /&gt;&lt;br /&gt;The change I did in the existing project can be downloaded by clicking &lt;a href="http://dnfug.com/Web/blogs/raheel/URL_TEST_updated.zip"&gt;URL_TEST_updated.zip&lt;/a&gt;&lt;br /&gt;------------------------&lt;br /&gt;&lt;br /&gt;There are other ways for the URL rewriting two, while IIS7 provides much better functionalities supporting the pageless URL re-writing &lt;br /&gt;&lt;br /&gt;You can have a look at &lt;a href="http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx"&gt;ScottGu&amp;#39;s Blog&lt;/a&gt; to have an indepth view of what other ways are there for URL re-writing as well.&lt;br /&gt;Othere Useful Links are &lt;br /&gt;&lt;a href="http://www.asp101.com/articles/matteo/urlrewriting/default.asp"&gt;http://www.asp101.com/articles/matteo/urlrewriting/default.asp&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.mattcutts.com/blog/asp-net-2-and-url-rewriting-sometimes-harmful/"&gt;http://www.mattcutts.com/blog/asp-net-2-and-url-rewriting-sometimes-harmful/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Cheers ! &lt;br /&gt;&lt;br /&gt;raheel Hussain&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://v900u039rux.maximumasp.com/Web/aggbug.aspx?PostID=72" width="1" height="1"&gt;</description><category domain="http://v900u039rux.maximumasp.com/Web/blogs/raheel/archive/tags/URL+Rewriting/default.aspx">URL Rewriting</category><category domain="http://v900u039rux.maximumasp.com/Web/blogs/raheel/archive/tags/SEO/default.aspx">SEO</category><category domain="http://v900u039rux.maximumasp.com/Web/blogs/raheel/archive/tags/Global_2E00_asax/default.aspx">Global.asax</category></item></channel></rss>