Reference to Virtual Root path not working

J

John Kotuby

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...
 
A

Aidy

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

use

<asp:Hyperlink ID="myLink" NavigateUrl="~/Common/ListView.aspc"
runat="server">click here</asp:Hyperlink>
 
A

Aidy

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.
 
S

SAL

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

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

S
 
J

John Kotuby

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.
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

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>
 
S

SAL

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top