Friday, May 3, 2013

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.


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

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog


My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews