« Previous Next »

Thread: Converting my existing asp.net 2.0 app to support urlrewrite module

Last post 04-02-2009 6:09 AM by haroonkhan. 5 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (6 items)

Sort Posts:

  • 03-26-2009, 8:33 PM

    Converting my existing asp.net 2.0 app to support urlrewrite module

    Hi, I have web application with about 250 pages and i want to start implementing URL Rewriting using URLRewrite module. I have read all the basics in http://learn.iis.net/page.aspx/460/using-url-rewrite-module/  and tested the examples and they worked fine.
    Now when I am trying to actually implement url rewriting to my site I have come across diffrent problems and have confusions. For now i have following quesions for which i ll be needing urgent answers.

    1. I have developed my appliation in asp.net 2.0 in visual studio 2005, but it is mentioned in http://learn.iis.net/page.aspx/460/using-url-rewrite-module/ that ASP.NET updates tha come with the module to fix bugs are only for verision 3.5 or heigher. Does It mean i have to switch my site to asp.net 3.5?? Please anyone clarify

    2. I have made a simple rule for testing as follows
    <rule name="City">
    <match url="city/([0-9])/([_0-9a-z-]+)" />
    <action type="Rewrite" url="city.aspx?city={R:1}&amp;cityname={R:2}" />
    </rule>

    it works fine, but as expected the images are not being displayed for example i have img tag in a repeater control which is bound like this

    <img src='<%#"Images/Cities/"+cstr(DataBinder.Eval(Container.DataItem,"ID"))+DataBinder.Eval(Container.DataItem,"ImageName")%>' />

    it is parsed like this in browser http://localhost/myap/City/1/Images/Cities/1/someimage.jpg
    Similarly i have <a> tag inside repeater databound control bounded like this

    <a href='<%# "Citydetail.aspx?city="+cstr(DataBinder.Eval(Container.DataItem,"Id"))+"&name="+DataBinder.Eval(Container.DataItem,"Name") %>'><%# DataBinder.Eval(Container.DataItem,"Name") %></a>
     what i m getting in browser is something like this <a href='http://localhost/myapp/City/1/citydetail.aspx?id=1&name=NewYork' ></a>
     Please someone guide me how to fix these issues.

     3. This is how I m refrencing javascript files in html head tag

    <script src="Scripts/common.js"></script>. Please someoen suggest how script files should be refrenced.

    These are the urgent quesions i have. Anyone who helps ll be greatly appreciated.

    Thanks

  • 03-27-2009, 1:00 PM In reply to

    • DanielVL
    • Top 75 Contributor
    • Joined on 10-07-2006, 6:00 PM
    • Redmond, WA, USA
    • Posts 109

    Re: Converting my existing asp.net 2.0 app to support urlrewrite module

    You need to install the ".NET Framework 3.5 SP1"; you don't need to modify your site or upgrade it.

    After installing the .NET Framework 3.5 SP1, please re-run the Rewrite Setup (Repair mode should work) so we can install a fix that is only installed if .NET Framework 3.5 SP1 is installed.

    After doing all this, check if you still have the issue #2.

     

    Daniel Vasquez Lopez
    URL Rewrite Engine Developer
  • 03-27-2009, 1:01 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 3:38 PM
    • Redmond, WA
    • Posts 651

    Re: Converting my existing asp.net 2.0 app to support urlrewrite module

    1. The hotfix for ASP.NET that are included with URL rewriter fix how the Request.RawUrl is set and how server side links with "~" symbol are resolved when using URL Rewriter. If you do not rely on those features in your application then it may not be necessary for you to update to 3.5.

    2. and 3. The possible way to fix these is to change your application to use absolute URL's instead of relative ones (note the forward slash).:

     <img src='<%#"/Images/Cities/"+cstr(DataBinder.Eval(Container.DataItem,"ID"))+DataBinder.Eval(Container.DataItem,"ImageName")%>' />

    <a href='<%# "/Citydetail.aspx?city="+cstr(DataBinder.Eval(Container.DataItem,"Id"))+"&name="+DataBinder.Eval(Container.DataItem,"Name") %>'><%# DataBinder.Eval(Container.DataItem,"Name") %></a>

    <script src="/Scripts/common.js"></script>.

    http://ruslany.net
  • 03-27-2009, 4:45 PM In reply to

    Re: Converting my existing asp.net 2.0 app to support urlrewrite module

    Thanks a lot both of you replying my post. Using Absolute Urls (with forward slash) is working but only if i include name of Virtual Directory with it also. For example this is my application path http://localhost/myap/city/1/newyork . When I am putting just Forward slash "/" while refrencing images and javascript files the link become something like this in the rendered html http://localhost/images/city/1/image.jpg instead of http://localhost/myap/images/city/1/image.jpg . Any idea how to resolve this issue?

    Thanks a lot

  • 03-30-2009, 4:25 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 3:38 PM
    • Redmond, WA
    • Posts 651

    Re: Converting my existing asp.net 2.0 app to support urlrewrite module

    Yes, when you use absolute paths in the links, you will have to take into account the application path when you application is located not in the root folder of the web site. I do not know of any workarounds to simplify that.

    ASP.NET has a "~" path, which allows you to specify link paths relative to the root of you web application. But for that I think you will need to use server side controls, e.g.

    <asp:Image imageUrl="~/images/city/1/image.jpg" />,

    <asp:HyperLink navigateUrl="~/somelink/somedoc.aspx" />

    For the "~" symbol to work properly with URL rewriter you will need to upgrade to .NET Framework 3.5 SP1 and then apply the update for ASP.NET as described in the Daniel's reply.

    http://ruslany.net
  • 04-02-2009, 6:09 AM In reply to

    Re: Converting my existing asp.net 2.0 app to support urlrewrite module

    Using "~" with server side controls is working fine. Only problem is using the absolute Path "/" with non server side controls as I mentioned above.. Because I don't wnat to use unnecessary servide controls (for example in a datagrid or repeater), so what I am planning is to have a Global variable containing application Name for Example AppName="/MyApp/" and prefixing it to the urls for example <a href ='<%#AppName+"somelink/somedoc.aspx"%>' >my doc</a>.

    If someone has a better solution then can suggest.

    Thanks once again for your support and Help

Page 1 of 1 (6 items)
Microsoft Communities