Server.Mappath returns path on local drive instead of server drive? (ASP.NET)

  • Thread starter Thread starter Jon
  • Start date Start date
J

Jon

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
mapped drive: M:\

And at this browser URL:
http://mrs2/P2M/login.aspx

I expected MapPath to map a path on the server where the application's
running, in this case the mapped drive M.

However, it returns a path based on my local drive, which is the dev
server but has nothing to do with where the application lives when I'm
running it:

c:\inetpub\wwwroot\p2m\Reports

Can someone explain this? Again, I had expected a M: path, not
anything local and thought that server.mappath had nothing to do with
my local system.

Jon
 
Scott, I understand your point but it's returning the WRONG physical
path. The application is running on a remote server (M:), and it's
returning a path on my local drive (C:).
 
What drive is the actual file in question located? Also, you've got just
"Reports" written here. That is the file name you are looking for? No
extension?
 
Interestingly, that thread you point to includes my responses to that other
developer from 7 years ago!

Unfortunatley, the answers are still the same:

Server.MapPath("relativePath") returns the physical path of the resource
specified on the machine where the code is executing.

If your code were running on some server "B" out there, how in the world
would information about your local machine "A" be returned? Server "B" has
no information about your local machine "A". If your results are coming
back refering to local machine "A", then that is where your code is
executing OR somewhere else in your code, you are statically pointing to
your local machine.

Let's see your code.

-Scott M.
 
To be more clear...If you want to get the full, physcial path of an image on
some server, you need to use Server.MapPath("relativePath") in code that
will execute ON THAT SERVER.

If you intend to run this code from your own machine, in the hopes of
getting the full, physical path of the image on some remote server, then
Server.MapPath won't help you.

Generally, full, physical paths should NOT BE KNOWN to applications and
users that don't have permission to exectue code on that server.

-Scott
 
Back
Top