469,955 Members | 2,576 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,955 developers. It's quick & easy.

Server.MapPath returning wrong path

I've got the directory f:\Company\Product set as web shared so it's got a
virtual directory in the default web site on my test server's IIS. If I try
to use Server.MapPath in that site it returns a path within
c:\Inetpub\wwwroot rather than the real path.

Can anyone please tell me why this isn't working?

Regards,
John
Jul 19 '05 #1
13 13957
Server.MapPath uses the root of the default web site as its determination of
the local folder. It doesn't actually look at individual virtual
directories, for some bizarre reason... I think it's a bug.


"John Rebbeck" <jo**@rebent.com> wrote in message
news:On**************@TK2MSFTNGP11.phx.gbl...
I've got the directory f:\Company\Product set as web shared so it's got a
virtual directory in the default web site on my test server's IIS. If I try to use Server.MapPath in that site it returns a path within
c:\Inetpub\wwwroot rather than the real path.

Can anyone please tell me why this isn't working?

Regards,
John

Jul 19 '05 #2
Any way to get around it?

"Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:eW**************@tk2msftngp13.phx.gbl...
Server.MapPath uses the root of the default web site as its determination of the local folder. It doesn't actually look at individual virtual
directories, for some bizarre reason... I think it's a bug.


"John Rebbeck" <jo**@rebent.com> wrote in message
news:On**************@TK2MSFTNGP11.phx.gbl...
I've got the directory f:\Company\Product set as web shared so it's got a virtual directory in the default web site on my test server's IIS. If I

try
to use Server.MapPath in that site it returns a path within
c:\Inetpub\wwwroot rather than the real path.

Can anyone please tell me why this isn't working?

Regards,
John


Jul 19 '05 #3
I'm not sure but what does using the Server Variable
APPL_PHYSICAL_PATH produce?

I think the syntax would be:
Response.Write Request.ServerVariables("APPL_PHYSICAL_PATH ")
Be double check that to be sure.
--

Phillip Windell [CCNA, MVP, MCP]
pw******@wandtv.com
WAND-TV (ABC Affiliate)
www.wandtv.com

"John Rebbeck" <jo**@rebent.com> wrote in message
news:#N**************@TK2MSFTNGP09.phx.gbl...
Any way to get around it?

"Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:eW**************@tk2msftngp13.phx.gbl...
Server.MapPath uses the root of the default web site as its determination
of
the local folder. It doesn't actually look at individual virtual
directories, for some bizarre reason... I think it's a bug.


"John Rebbeck" <jo**@rebent.com> wrote in message
news:On**************@TK2MSFTNGP11.phx.gbl...
I've got the directory f:\Company\Product set as web shared so
it's got
a virtual directory in the default web site on my test server's

IIS. If I try
to use Server.MapPath in that site it returns a path within
c:\Inetpub\wwwroot rather than the real path.

Can anyone please tell me why this isn't working?

Regards,
John



Jul 19 '05 #4
> > "Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:eW**************@tk2msftngp13.phx.gbl...
Server.MapPath uses the root of the default web site as its determination
of
the local folder. It doesn't actually look at individual virtual
directories, for some bizarre reason... I think it's a bug.


"John Rebbeck" <jo**@rebent.com> wrote in message
news:On**************@TK2MSFTNGP11.phx.gbl...
> I've got the directory f:\Company\Product set as web shared so

it's got
a
> virtual directory in the default web site on my test server's

IIS. If I try
> to use Server.MapPath in that site it returns a path within
> c:\Inetpub\wwwroot rather than the real path.
>
> Can anyone please tell me why this isn't working?
>
> Regards,
> John
>


I can't duplicate this behavior. MapPath always returns the correct path for
me. Maybe John could post his code and physical directory structure?

--
Mark Schupp
--
Head of Development
Integrity eLearning
Online Learning Solutions Provider
ms*****@ielearning.com
http://www.ielearning.com
714.637.9480 x17


Jul 19 '05 #5
"Mark Schupp" <ms*****@ielearning.com> wrote in message
news:ev**************@TK2MSFTNGP11.phx.gbl...
I can't duplicate this behavior. MapPath always returns the correct path for me. Maybe John could post his code and physical directory structure?


I've had it do that same to me. If you run a site from a Virtual
Folder instead of an actual Site the MapPath would use the parrent
Site as the starting point instead of the Virtual Directory root. This
is what you would run into with, say, Win2000 Pro where the IIS is
limited to one site, so each separate website runs from its own
Virtual Directory.

I got around it by just switching the Home Directory of the only Site
to what ever I needed at the moment....it is only a developement
machine so that works fine for me.

--

Phillip Windell [CCNA, MVP, MCP]
pw******@wandtv.com
WAND-TV (ABC Affiliate)
www.wandtv.com
Jul 19 '05 #6
"Phillip Windell" <pw******@wandtv.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
....
I've had it do that same to me. If you run a site from a Virtual
Folder instead of an actual Site the MapPath would use the parrent
Site as the starting point instead of the Virtual Directory root. This
is what you would run into with, say, Win2000 Pro where the IIS is
limited to one site, so each separate website runs from its own
Virtual Directory.


Still not clear on what you mean by each separate "website" running in its
own virtual directory when you can only have a single web site on the
system. Do you mean that there is a way to make it look like there are
multiple sites on the system? What would the URLs to 2 separate "websites"
look like?

--
Mark Schupp
--
Head of Development
Integrity eLearning
Online Learning Solutions Provider
ms*****@ielearning.com
http://www.ielearning.com
714.637.9480 x17
Jul 19 '05 #7
Windows 2000 server (and I assume 2003) allow more than one site on a
computer, each usually has it's own public IP

Windows 2000 and XP professional only allow a single site (Default Web Site)
"Mark Schupp" <ms*****@ielearning.com> wrote in message
news:u$**************@TK2MSFTNGP09.phx.gbl...
"Phillip Windell" <pw******@wandtv.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
...
I've had it do that same to me. If you run a site from a Virtual
Folder instead of an actual Site the MapPath would use the parrent
Site as the starting point instead of the Virtual Directory root. This
is what you would run into with, say, Win2000 Pro where the IIS is
limited to one site, so each separate website runs from its own
Virtual Directory.


Still not clear on what you mean by each separate "website" running in its
own virtual directory when you can only have a single web site on the
system. Do you mean that there is a way to make it look like there are
multiple sites on the system? What would the URLs to 2 separate "websites"
look like?

--
Mark Schupp
--
Head of Development
Integrity eLearning
Online Learning Solutions Provider
ms*****@ielearning.com
http://www.ielearning.com
714.637.9480 x17

Jul 19 '05 #8
"Tom B" <sh*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Windows 2000 server (and I assume 2003) allow more than one site on a
computer, each usually has it's own public IP

Windows 2000 and XP professional only allow a single site (Default Web Site)
Yes, I know. What I am curious about is the configuration that is causing
the problem. I cannot duplicate it on my systems (2kpro or server).

I was trying to find out what the last poster meant by "If you run a site
from a Virtual Folder instead of an actual Site".

--
Mark Schupp
--
Head of Development
Integrity eLearning
Online Learning Solutions Provider
ms*****@ielearning.com
http://www.ielearning.com
714.637.9480 x17

"Mark Schupp" <ms*****@ielearning.com> wrote in message
news:u$**************@TK2MSFTNGP09.phx.gbl...
"Phillip Windell" <pw******@wandtv.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
...
I've had it do that same to me. If you run a site from a Virtual
Folder instead of an actual Site the MapPath would use the parrent
Site as the starting point instead of the Virtual Directory root. This
is what you would run into with, say, Win2000 Pro where the IIS is
limited to one site, so each separate website runs from its own
Virtual Directory.


Still not clear on what you mean by each separate "website" running in its own virtual directory when you can only have a single web site on the
system. Do you mean that there is a way to make it look like there are
multiple sites on the system? What would the URLs to 2 separate "websites" look like?

--
Mark Schupp
--
Head of Development
Integrity eLearning
Online Learning Solutions Provider
ms*****@ielearning.com
http://www.ielearning.com
714.637.9480 x17


Jul 19 '05 #9
> Still not clear on what you mean by each separate "website" running in its
own virtual directory when you can only have a single web site on the
system. Do you mean that there is a way to make it look like there are
multiple sites on the system? What would the URLs to 2 separate "websites"
look like?


No, do this.

Under the default web site, create a virtual directory called 'foo' which
points to somewhere *other* than your normal webroot (e.g. if you use
c:\inetpub\wwwroot\ for your webroot, create a folder called c:\whatever\
and use that folder).

Now, fuss with the permissions so you can run ASP from that folder, and
place an ASP file like this test.asp:

<%
response.write server.mappath("/foo/test.asp")
%>

When you run it, you'll see that it returns something like:

c:\inetpub\wwwroot\foo\test.asp

Instead of what I think it should return:

c:\whatever\test.asp
Jul 19 '05 #10
Aaron,

Still cannot duplicate it. I tried the following on my system against some
existing virtual dirs:

<%
Response.Write "Server.MapPath(""/global.asa""): " &
server.MapPath("/global.asa") & "<br>"
Response.Write "Server.MapPath(""kx_gowbt.asp""): " &
server.MapPath("kx_gowbt.asp") & "<br>"
Response.Write "Server.MapPath(""/kx/kx_gowbt.asp""): " &
server.MapPath("/kx/kx_gowbt.asp")
%>

Returns:

Server.MapPath("/global.asa"): C:\Inetpub\wwwroot\global.asa
Server.MapPath("kx_gowbt.asp"): C:\bw\careertracker\kx_gowbt.asp
Server.MapPath("/kx/kx_gowbt.asp"): C:\bw\careertracker\kx_gowbt.asp

Which, unless I am going completely ga-ga, is correct. Do you think there
could be a problem with a specific version of IIS? I am running Win2k/IIS5

--
Mark Schupp
--
Head of Development
Integrity eLearning
Online Learning Solutions Provider
ms******@ielearning.com
http://www.ielearning.com
714.637.9480 x17
"Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:eN**************@tk2msftngp13.phx.gbl...
Still not clear on what you mean by each separate "website" running in its own virtual directory when you can only have a single web site on the
system. Do you mean that there is a way to make it look like there are
multiple sites on the system? What would the URLs to 2 separate "websites" look like?


No, do this.

Under the default web site, create a virtual directory called 'foo' which
points to somewhere *other* than your normal webroot (e.g. if you use
c:\inetpub\wwwroot\ for your webroot, create a folder called c:\whatever\
and use that folder).

Now, fuss with the permissions so you can run ASP from that folder, and
place an ASP file like this test.asp:

<%
response.write server.mappath("/foo/test.asp")
%>

When you run it, you'll see that it returns something like:

c:\inetpub\wwwroot\foo\test.asp

Instead of what I think it should return:

c:\whatever\test.asp

Jul 19 '05 #11
"Mark Schupp" <ms*****@ielearning.com> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
Still cannot duplicate it. I tried the following on my system against some existing virtual dirs:


To make sure I'm sane ;) I tested it. Here is what I did.

Using Win2000 Pro (IIS only allows one Site, but multiple VFs)

Home path for the Default Website is "C:\Inetpub\wwwroot"

Created a Virtual Folder called "Test"
Home path for Virtual Folder is "D:\Temp"

Created an ASP file called Test.asp and placed it in "D:\Temp"

File contains the line:
<%Response.write Server.MapPath("/")%> & "<br>"

The output from the page is:
"C:\Inetpub\wwwroot"

I then added the line:
<%Response.Write Request.ServerVariables("APPL_PHYSICAL_PATH")%>

This produced:
"D:\Temp\"

So the final outcome is that using Server.MapPath will map to the Root
of the *Site*, while using
Request.ServerVariables("APPL_PHYSICAL_PATH") will map to the Root of
the *Virtual Folder*. So if the original poster of this thread uses
this instead of Server.MapPath his problem would be solved. Now I
assume that if either command is used from the Root of the Site they
will both produce the same results.

--

Phillip Windell [CCNA, MVP, MCP]
pw******@wandtv.com
WAND-TV (ABC Affiliate)
www.wandtv.com
Jul 19 '05 #12
Maybe I'm naive but when you use "/" aren't you asking for the root of the
site?

If you want the root of the virtual directory then you would need
"/<virtdir>/".

--
Mark Schupp
--
Head of Development
Integrity eLearning
Online Learning Solutions Provider
ms******@ielearning.com
http://www.ielearning.com
714.637.9480 x17
"Phillip Windell" <pw******@wandtv.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
"Mark Schupp" <ms*****@ielearning.com> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
Still cannot duplicate it. I tried the following on my system

against some
existing virtual dirs:


To make sure I'm sane ;) I tested it. Here is what I did.

Using Win2000 Pro (IIS only allows one Site, but multiple VFs)

Home path for the Default Website is "C:\Inetpub\wwwroot"

Created a Virtual Folder called "Test"
Home path for Virtual Folder is "D:\Temp"

Created an ASP file called Test.asp and placed it in "D:\Temp"

File contains the line:
<%Response.write Server.MapPath("/")%> & "<br>"

The output from the page is:
"C:\Inetpub\wwwroot"

I then added the line:
<%Response.Write Request.ServerVariables("APPL_PHYSICAL_PATH")%>

This produced:
"D:\Temp\"

So the final outcome is that using Server.MapPath will map to the Root
of the *Site*, while using
Request.ServerVariables("APPL_PHYSICAL_PATH") will map to the Root of
the *Virtual Folder*. So if the original poster of this thread uses
this instead of Server.MapPath his problem would be solved. Now I
assume that if either command is used from the Root of the Site they
will both produce the same results.

--

Phillip Windell [CCNA, MVP, MCP]
pw******@wandtv.com
WAND-TV (ABC Affiliate)
www.wandtv.com

Jul 19 '05 #13
Ok. Using Server.MapPath("\test\") produces the Root of the Virtual
folder which was "D:\Temp". I noticed that this leaves off the
trailing \ while APPL_PHYSICAL_PATH includes it.

So maybe the original poster was using:
Server.MapPath("\") & "\test\something.asp"
.... instead of:
Server.MapPath("\test\something.asp")

I just tried that and it does reproduce his problem.

I don't know, he never showed any code.
--

Phillip Windell [CCNA, MVP, MCP]
pw******@wandtv.com
WAND-TV (ABC Affiliate)
www.wandtv.com

"Mark Schupp" <ms*****@ielearning.com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
Maybe I'm naive but when you use "/" aren't you asking for the root of the site?

If you want the root of the virtual directory then you would need
"/<virtdir>/".

--
Mark Schupp
--
Head of Development
Integrity eLearning
Online Learning Solutions Provider
ms******@ielearning.com
http://www.ielearning.com
714.637.9480 x17
"Phillip Windell" <pw******@wandtv.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
"Mark Schupp" <ms*****@ielearning.com> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
Still cannot duplicate it. I tried the following on my system

against some
existing virtual dirs:


To make sure I'm sane ;) I tested it. Here is what I did.

Using Win2000 Pro (IIS only allows one Site, but multiple VFs)

Home path for the Default Website is "C:\Inetpub\wwwroot"

Created a Virtual Folder called "Test"
Home path for Virtual Folder is "D:\Temp"

Created an ASP file called Test.asp and placed it in "D:\Temp"

File contains the line:
<%Response.write Server.MapPath("/")%> & "<br>"

The output from the page is:
"C:\Inetpub\wwwroot"

I then added the line:
<%Response.Write Request.ServerVariables("APPL_PHYSICAL_PATH")%>
This produced:
"D:\Temp\"

So the final outcome is that using Server.MapPath will map to the Root of the *Site*, while using
Request.ServerVariables("APPL_PHYSICAL_PATH") will map to the Root of the *Virtual Folder*. So if the original poster of this thread uses this instead of Server.MapPath his problem would be solved. Now I
assume that if either command is used from the Root of the Site they will both produce the same results.

--

Phillip Windell [CCNA, MVP, MCP]
pw******@wandtv.com
WAND-TV (ABC Affiliate)
www.wandtv.com


Jul 19 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by JR | last post: by
6 posts views Thread by Nathan Sokalski | last post: by
3 posts views Thread by Cozmo | last post: by
14 posts views Thread by Lorenzo | last post: by
4 posts views Thread by vunet.us | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.