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 asp.net.  You can find more information about Server.MapPath from the following location.

http://msdn.microsoft.com/en-us/library/ms524632(v=vs.90).aspx

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.


http://msdn.microsoft.com/en-IN/library/system.web.hosting.hostingenvironment.mappath.aspx

You can use HostingEnvironment.MapPath like following.
HostingEnvironment.MapPath(path);

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

3 comments:

  1. Good to know...!!!

    ReplyDelete
  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.
    William

    ReplyDelete

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