Server.MapPath: Returning a URL instead of a HD Location

N

Nathan Sokalski

When using the Server.MapPath() method, the results being returned are given
as locations on my hard drive. I would like to be returned a result that is
a URL, in my case something like the following:

http://localhost/WebApplication1/WebForm1.aspx

Instead, I am recieving results that are something like the following:

c:/inetpub/wwwroot/WebApplication1/WebForm1.aspx

I realize that these are the same file for me, but do not want them to cause
problems when I move my site to a host other than my computer. Is there a
way I can get MapPath to return a URL rather than a file directory?
 
N

Nathan Sokalski

It looks like FilePath is a property rather than a method, so how do I pass
it the info that I passed to Server.MapPath?
 
N

Nathan Sokalski

My basic problem is that I want to use the MakeRelative method of the Uri
class. To do this, I am making a Uri of the URL I want to go to. However,
because Visual Studio makes the project in a subdirectory of localhost,
which is where I am testing my project, but my finished site will be going
on http://www.nathansokalski.com/, I cannot enter an absolute URL like the
Uri constructor requires without needing to change all the Uri's in my site.
To avoid this problem, I am creating the Uri's as follows:

Dim targetURL As New Uri(Server.MapPath("images/frog.gif"))



So that I can create the Uri using a relative path and have the appropriate
domain & subdirectory added automatically. However, because the
Server.MapPath() method is returning a location on my hard drive, the
following command returns a String that is the same as that returned by
Server.MapPath() (with File:/// in front of it) rather than one that is
relative to the current URL:



HttpContext.Current.Request.Url.MakeRelative(targetURL)



After experimenting with the Uri class and its MakeRelative method, I have
concluded that if I could replace the Server.MapPath with something that
returned an URL that started with http:// instead of c: then the
MakeRelative method would return what I want. So my basic reason for using
Server.MapPath is to allow myself to test my application in any directory
and then transfer it to my actual site without changing all the Uri's.
Thanks.
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top