Y a-t-il une différence entre Server.MapPath()
et HostingEnvironment.MapPath()
? Est- Server.MapPath()
que Server.MapPath()
présente des avantages par rapport à HostingEnvironment.MapPath()
?
Mon problème initial était de mapper le chemin du fichier sur un serveur lorsque HttpContext
pas présent et que je ne pouvais pas transmettre une variable de Server
de Global.asax
à ma méthode.
J’ai HostingEnvironment.MapPath()
utilisé HostingEnvironment.MapPath()
car il n’a pas besoin de HttpContext
. Y a-t-il des situations où ces deux méthodes donneront des résultats différents?
Server.MapPath()
appelle finalement HostingEnvironment.MapPath()
, mais crée un object VirtualPath
avec des options spécifiques:
L’object
VirtualPath
transmis àHostingEnvironment.MapPath()
est construit commeHostingEnvironment.MapPath()
:VirtualPath.Create(path, VirtualPathOptions.AllowAllPath|VirtualPathOptions.AllowNull);
Modifier : en réalité, la seule différence est que vous êtes autorisé à transmettre null à Server.MapPath()
, mais pas à HostingEnvironment.MapPath()
Server.MapPath()
requirejs un HttpContext
. HostingEnvironment.MapPath
ne le fait pas.