Is there any difference between Server.MapPath()
and HostingEnvironment.MapPath()
? Does Server.MapPath()
have any advantages over HostingEnvironment.MapPath()
?
My original problem was mapping the file path on a server when the HttpContext
is not present and I cannot pass a Server
variable from Global.asax
to my method.
I used HostingEnvironment.MapPath()
instead since it doesn't need HttpContext
. Are there any situations when these two methods will give different results?
Best Solution
Server.MapPath()
eventually callsHostingEnvironment.MapPath()
, but it creates aVirtualPath
object with specific options:Edit: in reality, the only difference is that you are allowed to pass null to
Server.MapPath()
, but not toHostingEnvironment.MapPath()