473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 14283
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Elie Grouchko | last post by:
Hi I am running exactly the same ASP code on IIS 5.0 and IIS 6.0 I am calling Server.MapPath(), the parameter is a virtual path that includes a reference to a parent path...
3
by: Jon | last post by:
I'm calling Server.MapPath from global.asa through this line of code: Application("reports_dir") = Server.MapPath("Reports") The web application opens on a testing web server (not mine) at this...
6
by: JR | last post by:
My IIS Web site has a virtual directory called content mapped to a network share. If the home directory of the Web site is c:\inetpub\wwwroot and the virtual directory maps to the network share...
6
by: Nathan Sokalski | last post by:
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...
3
by: Cozmo | last post by:
We have an .asp application , located in: e:\myapp In there we have directories like: e:\myapp\db e:\myapp\images e:\myapp\utils e:\myapp\working
14
by: Lorenzo | last post by:
Hello, I have a web application with a virtual directory in it. With 'virtual directory' i mean a folder whose physical path is different from the physical path of the application, but in which...
4
by: vunet.us | last post by:
How to use server.mappath() parent folder correctly: Server.MapPath("../test.asp") Thank you for the hint.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.