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:

4 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.

About Me
My Photo

Full Stack Developer,Blogger,Microsoft Mvp, Mentor, Life long learner, 10+ Years of Experience for JavaScript, web and Microsoft technologies. ASP.NET MVC,Web Forms,C#,AngularJs,Golang
Mvp profile
Subscribe to my blog

Enter your email address:

Follow us on facebook
Blog Archive
Total Pageviews