Relative-to-root path messed up with VWDX server

Last post 06-05-2006 5:00 AM by SomeNewKid. 12 replies.

Sort Posts:

  • Huh? [:^)] Relative-to-root path messed up with VWDX server

    11-21-2005, 8:50 PM
    • Participant
      1,136 point Participant
    • Hondaman900
    • Member since 12-31-2002, 11:56 PM
    • Sacramento, California
    • Posts 228

    When I would run my apps with Web Matrix, the page would run under localhost on the Web Matrix dev server. Now VWDX appends the physical directory of my aspx files to localhost, using the directory name as a virtual directory (so running from say "MyApp" directory, the application root is now localhost/MyApp). The net-net is that my relative paths are off.

    I use FreeTextBox, which has it's images in a nested series of directories under <root>/images/...etc.... When the app runs in it's own folder, FreeTextBox expects it's images to be in localhost/images/...etc.... , while the actual image files are in localhost/MyApp/images/...etc....  because of the new weird root of the VWDX dev server. Placing a copy of the images directory one up from MyApp doesn't help either.

    Hope this makes sense.

    Any suggestions, and why is this happening?

    Stephen

    Stephen
  • Re: Relative-to-root path messed up with VWDX server

    11-21-2005, 9:13 PM
    • All-Star
      45,854 point All-Star
    • SomeNewKid
    • Member since 08-10-2003, 12:16 AM
    • Western Australia
    • Posts 8,027

    Stephen, if you want to send me an email, I will send to you an article I have written about this and the code to fix root-relative paths in an ASP.NET application. The article is not yet published online, so I cannot point you to it.
     

    Alister
  • Yes [Yes] Re: Relative-to-root path messed up with VWDX server

    11-21-2005, 9:59 PM
    • Participant
      1,136 point Participant
    • Hondaman900
    • Member since 12-31-2002, 11:56 PM
    • Sacramento, California
    • Posts 228
    Thank you, that would be helpful. Please e-mail to stephen@mediaq.net

    Thanks
    Stephen
  • Re: Relative-to-root path messed up with VWDX server

    11-22-2005, 12:23 AM
    • All-Star
      45,854 point All-Star
    • SomeNewKid
    • Member since 08-10-2003, 12:16 AM
    • Western Australia
    • Posts 8,027
    I have sent you the article and the code. I hope it helps you.
     

    Alister
  • Re: Relative-to-root path messed up with VWDX server

    11-22-2005, 1:22 AM
    • Star
      14,598 point Star
    • ScottGu
    • Member since 06-05-2002, 8:36 PM
    • Redmond, WA
    • Posts 2,004
    • AspNetTeam
      Moderator
    Here is a blog post I just made on how to fix it too; http://weblogs.asp.net/scottgu/archive/2005/11/21/431138.aspx

    Hope this helps,

    Scott
  • Re: Relative-to-root path messed up with VWDX server

    11-22-2005, 2:34 AM
    • All-Star
      45,854 point All-Star
    • SomeNewKid
    • Member since 08-10-2003, 12:16 AM
    • Western Australia
    • Posts 8,027
    Scott, speaking of root-relative paths, I wonder if I might ask you a related question?

    My web application serves multiple websites by employing URL rewriting. The folder structure of my web application is like this:

        /root
            /sites
                /example1.com
                /example2.com

    If a user requests www.example1.com/default.aspx from her browser, my URL rewriting code will use HttpContext.Current.RewritePath() to change the path from /default.aspx to /sites/example1.com/default.aspx. This is an easy and well-known technique.

    In that default.aspx page, I can include the following root-relative path:

        <img src="/images/logo.gif" />

    My URL rewriting code will again intercept this request (a wildcard mapping in IIS passes all requests to my ASP.NET app), and will resolve the path to /sites/example1.com/images/logo.gif. This is simple stuff.

    The problem comes with things like the following Page and User Control directives:

        <%@ Page MasterPageFile="/Default.master" %>
        <%@ Register TagPrefix="My" TagName="UserControl" Src="/MyUserControl.aspx" %>

    In both cases, the path will resolve to the application /root folder rather than the "rewritten" root folder of /sites/example1.com/.

    I have been peeking about in the ASP.NET framework using Reflector, and scouring the MSDN documentation, but I just cannot see how I can change the way these paths resolve. Do you know whether it is possible to change the way these paths resolve?
     
    Alister
  • Re: Relative-to-root path messed up with VWDX server

    11-23-2005, 11:17 AM
    • Contributor
      5,791 point Contributor
    • davidebb
    • Member since 06-11-2002, 12:31 PM
    • Redmond, WA
    • Posts 1,161
    • AspNetTeam
    Hi Alister,

    I hadn't seen this specific pattern used before.  It may be possible to solve this using a VirtualPathProvider, though it will be a little non-trivial.  Before we get to that, I'm curious about the reasons for using this pattern.  Wouldn't it be simpler to use a different ASP.NET application to serve each site, instead of only using one and having to deal with these path rewriting issues?  The one reason I can think of to do this is if you have a very large number of sites, in which case you will scale better with a single app.  Is that your situation?

    thanks,
    David
  • Re: Relative-to-root path messed up with VWDX server

    11-26-2005, 7:42 PM
    • All-Star
      45,854 point All-Star
    • SomeNewKid
    • Member since 08-10-2003, 12:16 AM
    • Western Australia
    • Posts 8,027
     davidebb wrote:
    The one reason I can think of to do this is if you have a very large number of sites, in which case you will scale better with a single app.  Is that your situation?
    Yes, that is precisely my situation. I create small, personal websites. It is unnecessarily expensive to purchase a new hosting plan for each and every new website. It is more economical to purchase one advanced hosting plan, and allow its single ASP.NET application to drive a number of separate websites. This works today, and works fine.

    I then attempted to install the Personal Site Starter Kit as a "child" site:

        /root
            /bin
                personal-site.dll
                example1.dll
            /sites
                /personal.com
                    default.aspx
                /example1.com
                    default.aspx

    I started removing all of the tilde-based paths from the Personal Site Starter Kit, and then questioned whether I could instead change the behaviour of the tilde-based paths. I hit the framework with Reflector, but could not find an "overridable point" that would allow me to change the way tilde-based paths resolve.

    I don't mind a non-trivial solution. But even with a provider pattern solution, I don't see how I can affect the behaviour of the System.Web.UI classes that resolve a tilde-based path. If you can provide any clues, I'd be very grateful.
     
    Alister
  • Re: Relative-to-root path messed up with VWDX server

    11-27-2005, 11:50 PM
    • Contributor
      5,791 point Contributor
    • davidebb
    • Member since 06-11-2002, 12:31 PM
    • Redmond, WA
    • Posts 1,161
    • AspNetTeam

    Hi Alister,

    I think this is a good topic that could be of interest to others, so I wrote a blog entry to discuss a possible solution using VirtualPathProvider.

    Hope this helps, and feel free to follow up on the blog.

    David

     

  • Re: Relative-to-root path messed up with VWDX server

    11-29-2005, 3:35 AM
    • All-Star
      45,854 point All-Star
    • SomeNewKid
    • Member since 08-10-2003, 12:16 AM
    • Western Australia
    • Posts 8,027
    First, to Scott, thank you for pointing a member of your team to this thread. I genuinely appreciate it.

    Second, to David, thank you for researching an answer to my question. The VirtualPathProvider option does indeed solve one-half of the problem. To solve the other half requires updating the base class of any "child" .aspx pages. I have added a reply to your blog entry regarding this "other half".

    With your help, the pages of my child sites are working as though they were of "root-level" sites. That is, the tilde-based paths are resolving into each site's pseudo-root folder, rather than the application's true root folder. This is precisely the behaviour I was looking to implement.

    Thank you, guys! I am truly grateful for your help.
     
    Alister
  • Re: Relative-to-root path messed up with VWDX server

    04-05-2006, 11:32 PM
    • All-Star
      45,854 point All-Star
    • SomeNewKid
    • Member since 08-10-2003, 12:16 AM
    • Western Australia
    • Posts 8,027
    SomeNewKid:
    Stephen, if you want to send me an email, I will send to you an article I have written about this and the code to fix root-relative paths in an ASP.NET application. The article is not yet published online, so I cannot point you to it.
    Just in case anyone stumbles upon this thread, I've since put the article and its code download on my website: Using Root-Relative Paths in ASP.NET
     
    Alister
  • Re: Relative-to-root path messed up with VWDX server

    06-05-2006, 2:35 AM
    • Member
      5 point Member
    • sonurijs
    • Member since 06-05-2006, 6:27 AM
    • Posts 1

    hello Friend,

     

              Can u send me the above said article to me as i am in urgent need regarding change of relative path. what i want to do is i have two folders of images (for example one and two)

    Form1.aspx

    One(Folder) - File.jpg

    Two(Folder) - File.jpg

    Form1.aspx has an image for File.jpg. if the file exists in folder One, then it should be loaded. or if the file does not exists in the folder One, then it should use folder Two for the image. this i have to implement in common for all the images in my solution.

    please help me in this regard,

    thanks for the solution

    Sonnu

  • Re: Relative-to-root path messed up with VWDX server

    06-05-2006, 5:00 AM
    • All-Star
      45,854 point All-Star
    • SomeNewKid
    • Member since 08-10-2003, 12:16 AM
    • Western Australia
    • Posts 8,027
    sonurijs:
    Can u send me the above said article to me
    If you are referring to my article, you may read it here: Using Root-Relative Paths in ASP.NET
     
    Alister
Page 1 of 1 (13 items)