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

Discussion in 'ASP .Net' started by Jon, Oct 23, 2003.

  1. Jon

    Jon Guest

    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
     
    Jon, Oct 23, 2003
    #1
    1. Advertising

  2. Jon

    Scott M. Guest

    Server.MapPath returns the full PHYSICAL path of the relative path entered.


    "Jon" <> wrote in message
    news:...
    > 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 M., Oct 23, 2003
    #2
    1. Advertising

  3. Jon

    Jon Guest

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

    "Scott M." <> wrote in message news:<>...
    > Server.MapPath returns the full PHYSICAL path of the relative path entered.
    >
    >
    > "Jon" <> wrote in message
    > news:...
    > > 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
     
    Jon, Oct 23, 2003
    #3
  4. Jon

    Scott M. Guest

    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?


    "Jon" <> wrote in message
    news:...
    > 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:).
    >
    > "Scott M." <> wrote in message

    news:<>...
    > > Server.MapPath returns the full PHYSICAL path of the relative path

    entered.
    > >
    > >
    > > "Jon" <> wrote in message
    > > news:...
    > > > 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 M., Oct 24, 2003
    #4
  5. Jon

    Scott M. Guest

    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.


    "EnginMan205" <> wrote in message
    news:...
    > Hi, I'd like to copy an image on server drive but server.mappath returns
    > local physical address (on my computer). How I can use it to rerun right
    > address on server?
    >
    > From
    > http://www.developmentnow.com/g/8_2...cal-drive-instead-of-server-drive-ASP-NET.htm
    >
    > Posted via DevelopmentNow.com Groups
    > http://www.developmentnow.com/g/
     
    Scott M., Jan 17, 2010
    #5
  6. Jon

    Scott M. Guest

    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

    "EnginMan205" <> wrote in message
    news:...
    > Hi, I'd like to copy an image on server drive but server.mappath returns
    > local physical address (on my computer). How I can use it to rerun right
    > address on server?
    >
    > From
    > http://www.developmentnow.com/g/8_2...cal-drive-instead-of-server-drive-ASP-NET.htm
    >
    > Posted via DevelopmentNow.com Groups
    > http://www.developmentnow.com/g/
     
    Scott M., Jan 17, 2010
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    2,248
  2. =?Utf-8?B?dHBhcmtzNjk=?=

    server.mappath vs. request.mappath

    =?Utf-8?B?dHBhcmtzNjk=?=, Mar 10, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    1,156
    Juan T. Llibre
    Mar 11, 2007
  3. shailesh
    Replies:
    1
    Views:
    789
    Tim Golden
    Mar 28, 2007
  4. Replies:
    4
    Views:
    971
    Juan T. Llibre
    Oct 7, 2007
  5. Blake
    Replies:
    1
    Views:
    160
    Ray at
    Apr 15, 2004
Loading...

Share This Page