Reputation: 3945
looking to use :
fileMap.ExeConfigFilename = System.Web.HttpContext.Current.Server.MapPath("~/Synchroniser/ConvertXML/App.config");
in my project. .HttpContext is flagging as namespace does not exist. I have looked at an old project where this works and have imported the same ref file to my references, but it is flagging with a yellow explainataion mark, also tried adding
using System.Web.Http;
using System.Web;
but no joy, any idea?
Upvotes: 0
Views: 673
Reputation: 131
HttpContext.Current.Server.MapPath should be replaced by HostingEnvironment.MapPath and ref System.Web.Hosting to avoid using httpcontext
Upvotes: 0
Reputation: 1039498
Make sure that your project is targeting the full .NET 4.0 instead of the Client Profile:
Now, you need to add a reference to the System.Web
assembly and using System.Web
to the file:
All this being said, please note that it's an absolutely abominable thing to do. Your class libraries (a.k.a DAL, BAL, whatever ...) should have strictly no knowledge about any HttpContext. That's purely web stuff and should live only where it belongs - to the web tier.
Your DAL, BAL, ... should not be doing any System.Web.HttpContext.Current.Server.MapPath
calls. It should simply be taking the filename as parameter. The way this filename is calculated is purely the responsibility of the caller. So if the caller is a web application it could use the MapPath
method. If the caller is a desktop application it should use something else. If it is a Windows Phone application it should use another thing. See how now your DAL, BAL, ... is agnostic of the caller and far more reusable?
Upvotes: 1