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

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
 
J

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:).
 
S

Scott M.

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?
 
S

Scott M.

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.
 
S

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
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top