views:

863

answers:

2

Hi,

I wanted to ask what if there is any difference between Server.MapPath and HostingEnvironment.MapPath? Does Server.MapPath have any advantages over HostingEnvironment.MapPath?

My original problem was mapping file path on a server when context is not present and I cannot pass 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?

Thanks in advance for help.

+2  A: 
Philippe Leybaert
So I will always get same results from both methods, right? (excluding null argument)
empi
yes, you would.
Philippe Leybaert
+3  A: 

Server.MapPath requires an HttpContext. HostingEnvironment.MapPath does not.

Mark Struzinski