The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.
Many times we need to know the full path of remote server where we are hosting or the exact location of file but if we don't how we can't. Actually we have MapPath method which maps the specified relative or virtual path to the corresponding physical directory on the web server.
Server.MapPath()
eventually calls HostingEnvironment.MapPath()
, but it creates a VirtualPath
object with specific options:
The
VirtualPath
object passed toHostingEnvironment.MapPath()
is constructed like this:VirtualPath.Create(path, VirtualPathOptions.AllowAllPath|VirtualPathOptions.AllowNull);
Edit: in reality, the only difference is that you are allowed to pass null to Server.MapPath()
, but not to HostingEnvironment.MapPath()
Server.MapPath()
requires an HttpContext
. HostingEnvironment.MapPath
does not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With