简体   繁体   中英

Server.MapPath() can't go up 2 levels?

I've been studying this excellent Stack post about Server.MapPath() , and I can't find anything in there that takes me up 2 levels from the current location.

Server.MapPath("./"); // this works - current path
Server.MapPath("../"); // this works - parent path
Server.MapPath("/"); // this works - virtual root path (2 levels HIGHER than I need)
Server.MapPath(".../"); // This fails

Is there no way to go up 2 levels? (That would be the parent of the parent folder.)

Yes, I can accomplish this by going to the virtual root and then parsing/combining, but that seems hackish. Looking for something more elegant or canonical.

.. goes up on folder, so ../../ will go up two levels and so on.

Note that this will not let you go outside of your site's root folder: if page is "/foo/bar.aspx" trying to map "../.." will fail if your site is at the root.

In windows there is no .../ path.

  • ./ means the current directory
  • ../ means one level above

Note: You can think the quantity of . are the quantity of levels, but that isn't so.

2 Levels above are ../../ , 3 Levels ../../../ and so on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM