Server.Map alternative in WCF - HostingEnvironment.MapPath

If you are ASP.NET programmer then you already know about Server.MapPath. It is used to map a physical location on webserver for  You can find more information about Server.MapPath from the following location.

You can still use that in WCF(Windows Communication Foundation) service http bindings. As we know WCF Service can use other non http bindings like TCP/IP,MSMQ and Named Pipe. At that time HttpContext of WCF will be none so server.mappath will not be available as current context is not available. Because its a child class of HttpContext.Current.

HostingEnvironment.MapPath :

HostingEnvironment.MapPath works on all kind of bindings. So when you have other bindings like TCP/IP and MSMQ it will be available as it is inherited from the System.Web.Hosting namespace. You can find more information from below MSDN link.

You can use HostingEnvironment.MapPath like following.

That’s it. Hope you like it. Stay tuned for more..


  1. Good to know...!!!

  2. Hosting is the great article which is very essential for me as well. I am sure the content will be effective to me for learning about the content. Keep it up.


Post a Comment

Your feedback is very important to me. Please provide your feedback via putting comments.

Popular posts from this blog

How to create Rest API(Web API) with ASP.NET Core 1.0

Creating PDF with ASP.Net MVC and RazorPDF

Solution: gulp is not recognized as internal or external command- Visual Studio