What is the difference between Server.MapPath and HostingEnvironment.MapPath?
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.