Reference to Virtual Root path not working

Discussion in 'ASP .Net' started by John Kotuby, May 23, 2007.

  1. John Kotuby

    John Kotuby Guest

    Hi all..

    In a VS2005 ASP.NET 2.0 website application I am using a regular HTML anchor
    (actually a number of them) in a page that produces Excel output because a
    server control is really not needed here. I am using a relative path in the
    anchor such as:
    <a href= "/Common/ListView.aspx"

    My understanding is that I cannot use the syntax:

    <a href="~/Common/ListView.aspx"

    ....if I am not declaring a Server control. Maybe I am wrong there... but
    anyway...

    I want to create in Global.asax a session variable - UrlRoot - that I can
    reference anywhere in the application that holds the virtual root whether
    the app is running on my dev machine, a local testing server, or the remote
    production server like so ...

    <a href= UrlRoot & "/Common/ListView.aspx"

    I have tried:
    Session.Add("URL_Root", "http://" & Request.Url.Host)
    Session.Add("URL_Root", "http://" &
    HttpContext.Current.Request.ApplicationPath)
    Session.Add("URL_Root", VirtualPathUtility.ToAppRelative("/"))

    No matter what method I use or where I run the app the link dynamically
    created in the Excel file seems to be returning:

    http://localhost/Common/ListView.aspx
    rather than
    http://www.prodserv.com/Common/ListView.aspx

    Can anyone lend assistance? I need the URL_Root to return the root domain of
    what the User would type into the browser to get to the correct page.
    Thanks...
     
    John Kotuby, May 23, 2007
    #1
    1. Advertising

  2. John Kotuby

    Aidy Guest

    > <a href= "/Common/ListView.aspx"

    use

    <asp:Hyperlink ID="myLink" NavigateUrl="~/Common/ListView.aspc"
    runat="server">click here</asp:Hyperlink>
     
    Aidy, May 23, 2007
    #2
    1. Advertising

  3. John Kotuby

    Aidy Guest

    PS syntax is off the top of my head, not sure if that's write. Basically
    use a Hyperlink control rather than an anchor tag.

    "Aidy" <> wrote in message
    news:...
    >> <a href= "/Common/ListView.aspx"

    >
    > use
    >
    > <asp:Hyperlink ID="myLink" NavigateUrl="~/Common/ListView.aspc"
    > runat="server">click here</asp:Hyperlink>
    >
     
    Aidy, May 23, 2007
    #3
  4. John Kotuby

    SAL Guest

    Have you tried:
    Session.Add("URL_Root", Server.MapPath(""))

    Not sure if you can use it but maybe...

    S

    "John Kotuby" <> wrote in message
    news:...
    > Hi all..
    >
    > In a VS2005 ASP.NET 2.0 website application I am using a regular HTML
    > anchor (actually a number of them) in a page that produces Excel output
    > because a server control is really not needed here. I am using a relative
    > path in the anchor such as:
    > <a href= "/Common/ListView.aspx"
    >
    > My understanding is that I cannot use the syntax:
    >
    > <a href="~/Common/ListView.aspx"
    >
    > ...if I am not declaring a Server control. Maybe I am wrong there... but
    > anyway...
    >
    > I want to create in Global.asax a session variable - UrlRoot - that I can
    > reference anywhere in the application that holds the virtual root whether
    > the app is running on my dev machine, a local testing server, or the
    > remote production server like so ...
    >
    > <a href= UrlRoot & "/Common/ListView.aspx"
    >
    > I have tried:
    > Session.Add("URL_Root", "http://" & Request.Url.Host)
    > Session.Add("URL_Root", "http://" &
    > HttpContext.Current.Request.ApplicationPath)
    > Session.Add("URL_Root", VirtualPathUtility.ToAppRelative("/"))
    >
    > No matter what method I use or where I run the app the link dynamically
    > created in the Excel file seems to be returning:
    >
    > http://localhost/Common/ListView.aspx
    > rather than
    > http://www.prodserv.com/Common/ListView.aspx
    >
    > Can anyone lend assistance? I need the URL_Root to return the root domain
    > of what the User would type into the browser to get to the correct page.
    > Thanks...
    >
     
    SAL, May 23, 2007
    #4
  5. John Kotuby

    John Kotuby Guest

    Thanks SAL,

    I think that Server.MapPath will actually give me a machine path like
    C:\INETPUB\WWW\COMMON\ListView.apsx.
    It's usually used to get absolute path references for opening files with the
    File System Object and such.

    "SAL" <> wrote in message
    news:...
    > Have you tried:
    > Session.Add("URL_Root", Server.MapPath(""))
    >
    > Not sure if you can use it but maybe...
    >
    > S
    >
    > "John Kotuby" <> wrote in message
    > news:...
    >> Hi all..
    >>
    >> In a VS2005 ASP.NET 2.0 website application I am using a regular HTML
    >> anchor (actually a number of them) in a page that produces Excel output
    >> because a server control is really not needed here. I am using a relative
    >> path in the anchor such as:
    >> <a href= "/Common/ListView.aspx"
    >>
    >> My understanding is that I cannot use the syntax:
    >>
    >> <a href="~/Common/ListView.aspx"
    >>
    >> ...if I am not declaring a Server control. Maybe I am wrong there... but
    >> anyway...
    >>
    >> I want to create in Global.asax a session variable - UrlRoot - that I
    >> can reference anywhere in the application that holds the virtual root
    >> whether the app is running on my dev machine, a local testing server, or
    >> the remote production server like so ...
    >>
    >> <a href= UrlRoot & "/Common/ListView.aspx"
    >>
    >> I have tried:
    >> Session.Add("URL_Root", "http://" & Request.Url.Host)
    >> Session.Add("URL_Root", "http://" &
    >> HttpContext.Current.Request.ApplicationPath)
    >> Session.Add("URL_Root", VirtualPathUtility.ToAppRelative("/"))
    >>
    >> No matter what method I use or where I run the app the link dynamically
    >> created in the Excel file seems to be returning:
    >>
    >> http://localhost/Common/ListView.aspx
    >> rather than
    >> http://www.prodserv.com/Common/ListView.aspx
    >>
    >> Can anyone lend assistance? I need the URL_Root to return the root domain
    >> of what the User would type into the browser to get to the correct page.
    >> Thanks...
    >>

    >
    >
     
    John Kotuby, May 23, 2007
    #5
  6. Try adding the runat='server' attribute to your anchor tag. If I remember
    right that will translate the tilde(~) for you...
    <a href="~/Common/ListView.aspx" runat='"server">Click me</a>

    --
    I hope this helps,
    Steve C. Orr,
    MCSD, MVP, CSM, ASPInsider
    http://SteveOrr.net


    "John Kotuby" <> wrote in message
    news:...
    > Hi all..
    >
    > In a VS2005 ASP.NET 2.0 website application I am using a regular HTML
    > anchor (actually a number of them) in a page that produces Excel output
    > because a server control is really not needed here. I am using a relative
    > path in the anchor such as:
    > <a href= "/Common/ListView.aspx"
    >
    > My understanding is that I cannot use the syntax:
    >
    > <a href="~/Common/ListView.aspx"
    >
    > ...if I am not declaring a Server control. Maybe I am wrong there... but
    > anyway...
    >
    > I want to create in Global.asax a session variable - UrlRoot - that I can
    > reference anywhere in the application that holds the virtual root whether
    > the app is running on my dev machine, a local testing server, or the
    > remote production server like so ...
    >
    > <a href= UrlRoot & "/Common/ListView.aspx"
    >
    > I have tried:
    > Session.Add("URL_Root", "http://" & Request.Url.Host)
    > Session.Add("URL_Root", "http://" &
    > HttpContext.Current.Request.ApplicationPath)
    > Session.Add("URL_Root", VirtualPathUtility.ToAppRelative("/"))
    >
    > No matter what method I use or where I run the app the link dynamically
    > created in the Excel file seems to be returning:
    >
    > http://localhost/Common/ListView.aspx
    > rather than
    > http://www.prodserv.com/Common/ListView.aspx
    >
    > Can anyone lend assistance? I need the URL_Root to return the root domain
    > of what the User would type into the browser to get to the correct page.
    > Thanks...
    >
     
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider], May 23, 2007
    #6
  7. John Kotuby

    SAL Guest

    Right you are John. If you don't want to make these server controls, maybe
    you could parse the path to get what you need from it???

    S

    "John Kotuby" <> wrote in message
    news:...
    > Thanks SAL,
    >
    > I think that Server.MapPath will actually give me a machine path like
    > C:\INETPUB\WWW\COMMON\ListView.apsx.
    > It's usually used to get absolute path references for opening files with
    > the File System Object and such.
    >
    > "SAL" <> wrote in message
    > news:...
    >> Have you tried:
    >> Session.Add("URL_Root", Server.MapPath(""))
    >>
    >> Not sure if you can use it but maybe...
    >>
    >> S
    >>
    >> "John Kotuby" <> wrote in message
    >> news:...
    >>> Hi all..
    >>>
    >>> In a VS2005 ASP.NET 2.0 website application I am using a regular HTML
    >>> anchor (actually a number of them) in a page that produces Excel output
    >>> because a server control is really not needed here. I am using a
    >>> relative path in the anchor such as:
    >>> <a href= "/Common/ListView.aspx"
    >>>
    >>> My understanding is that I cannot use the syntax:
    >>>
    >>> <a href="~/Common/ListView.aspx"
    >>>
    >>> ...if I am not declaring a Server control. Maybe I am wrong there... but
    >>> anyway...
    >>>
    >>> I want to create in Global.asax a session variable - UrlRoot - that I
    >>> can reference anywhere in the application that holds the virtual root
    >>> whether the app is running on my dev machine, a local testing server, or
    >>> the remote production server like so ...
    >>>
    >>> <a href= UrlRoot & "/Common/ListView.aspx"
    >>>
    >>> I have tried:
    >>> Session.Add("URL_Root", "http://" & Request.Url.Host)
    >>> Session.Add("URL_Root", "http://" &
    >>> HttpContext.Current.Request.ApplicationPath)
    >>> Session.Add("URL_Root", VirtualPathUtility.ToAppRelative("/"))
    >>>
    >>> No matter what method I use or where I run the app the link dynamically
    >>> created in the Excel file seems to be returning:
    >>>
    >>> http://localhost/Common/ListView.aspx
    >>> rather than
    >>> http://www.prodserv.com/Common/ListView.aspx
    >>>
    >>> Can anyone lend assistance? I need the URL_Root to return the root
    >>> domain of what the User would type into the browser to get to the
    >>> correct page.
    >>> Thanks...
    >>>

    >>
    >>

    >
    >
     
    SAL, May 24, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Franks
    Replies:
    20
    Views:
    4,547
    doodilydoodily
    Dec 7, 2009
  2. cmay
    Replies:
    2
    Views:
    2,404
  3. Replies:
    9
    Views:
    524
    Juan T. Llibre
    Dec 7, 2006
  4. =?Utf-8?B?SmVmZiBCZWVt?=

    physical path to virtual path under virtual directory

    =?Utf-8?B?SmVmZiBCZWVt?=, Aug 1, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    1,093
    Eliyahu Goldin
    Aug 1, 2007
  5. Guest

    Virtual Path and physical root

    Guest, Aug 2, 2004, in forum: ASP General
    Replies:
    4
    Views:
    235
    Guest
    Aug 2, 2004
Loading...

Share This Page