0

In our ASP.NET application, we use this code:

Server.MapPath("/") = C:\myappsFolder\myapp\web\

But, how come Server.MapPath("/Token") returns the following ?

Server.MapPath("/Token") = C:\myappsFolder\myOtherFolder\myapp\tkn 

I would think Server.MapPath("/Token") should return

C:\myappsFolder\myapp\web\Token 

Thank you

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
faujong
  • 949
  • 4
  • 24
  • 40
  • How are you running your application? Under IIS or IIS Express? Or some other host server? Is this when you launch from within Visual Studio? – Dai Jul 22 '22 at 00:21
  • Also, to resolve application-root-relative paths, use the `~/` prefix, e.g. `Server.MapPath("~/")` - what do you get for that? – Dai Jul 22 '22 at 00:22
  • I am running the application under IIS – faujong Jul 22 '22 at 02:11
  • Server.MapPath("~/") returns C:\myappsFolder\myapp\web\ – faujong Jul 22 '22 at 02:13

1 Answers1

0

I found the answer. There is a virtual directory Token that points to C:\myappsFolder\myOtherFolder\myapp\tkn

Thank you all for your answers

faujong
  • 949
  • 4
  • 24
  • 40
  • Just keep in mind that RARE pointed out that server mappath uses your current request context, so if your current page is nested, then mappath will give different results based on your current url. As a result of above, then one would be wise to use path name from Root such as ~/some path and not some path. In most cases it not noticeable, but most don't realize that mappath takes into account the current page and nesting you are on. So depending on what page you are on. Mappath can return different results when feeding it the same url – Albert D. Kallal Jul 22 '22 at 18:41