(IIS6) Server.MapPath(strPath) - Bug 4 folders not under /inetpub/wwwroot?

(IIS6) Server.MapPath(strPath) - Bug 4 folders not under /inetpub/wwwroot?

am 31.10.2007 19:19:30 von mravichandran

Dear Readers,

good afternoon. i am trying to identify the physical path
programmatically when my server application drops a file inside c:
\MyServer\MyServerOutput folder. this folder at the lowest level is a
virutal directory called 'myserveroutput'. i get a file name:
http://localhost/myserveroutput/filename.mdb. when i parse out the
string in a web application residing in http://localhost/myapplication/default.aspx
and try to do a server.mappath(~/myserveroutput), it returns a non-
existing path of c:\inetpub\wwwroot\myapplication\myserveroutput
\filename.mdb instead of going after c:\MyServer\MyServerOutput
\filename.mdb.

i searched on the internet for server.mappath() results and all
examples talk about the web application folder and the data folder
being under the c:\inetpub\wwwroot.

the iis console sees my myserveroutput being present c:\myserver
\myserveroutput\ folder correctly. i am only surprised whether it is
a bug in server.map(strpath) folder for folders not under \inetput
\wwwroot.

thanks and regards
Ravi.

Re: (IIS6) Server.MapPath(strPath) - Bug 4 folders not under /inetpub/wwwroot?

am 31.10.2007 23:29:23 von Anthony Jones

"Ravi, Dallas, Texas" wrote in message
news:1193854770.231903.66980@d55g2000hsg.googlegroups.com...
> Dear Readers,
>
> good afternoon. i am trying to identify the physical path
> programmatically when my server application drops a file inside c:
> \MyServer\MyServerOutput folder. this folder at the lowest level is a
> virutal directory called 'myserveroutput'. i get a file name:
> http://localhost/myserveroutput/filename.mdb. when i parse out the
> string in a web application residing in
http://localhost/myapplication/default.aspx
> and try to do a server.mappath(~/myserveroutput), it returns a non-
> existing path of c:\inetpub\wwwroot\myapplication\myserveroutput
> \filename.mdb instead of going after c:\MyServer\MyServerOutput
> \filename.mdb.
>
> i searched on the internet for server.mappath() results and all
> examples talk about the web application folder and the data folder
> being under the c:\inetpub\wwwroot.
>
> the iis console sees my myserveroutput being present c:\myserver
> \myserveroutput\ folder correctly. i am only surprised whether it is
> a bug in server.map(strpath) folder for folders not under \inetput
> \wwwroot.
>

This is not a bug.

The '~' alias represents the HttpApplication root folder. The
Default.aspx is running in application which as the root ' /myapplication;.
Hence '~/myserveroutput' is equivalent to '/myapplication/myserveroutput'.

Once the ~ alias has been resolved the physical path can be resolved. Since
'myapplication' is a physical folder under c:\inetpub\wwwroot then the
calculated physical path is
'c:\inetpub\wwwroot\myapplication\myserveroutput'. There is no requirement
for this folder to actually exist.

Try server.mappath("/myserveroutput") instead.

--
Anthony Jones - MVP ASP/ASP.NET