Having some problems trying to get HostingEnvironment.MapPath()
to work with my WCF app.
I created a class with a static method to check to see if HttpContext.Current
is null:
public class ServerPath
{
public static string MapPath(string path)
{
string result;
if (HttpContext.Current != null)
result = HttpContext.Current.Server.MapPath(path);
result = HostingEnvironment.MapPath(path);
return result;
}
}
and everything I through at it just returns null (ServerPath.MapPath(~/file.xml")
and Server.PathPath("./file.xml")
). If anyone is wondering why I have 'string result'; it is because I added if (string.IsNullOrEmpty(result))
and added result = Directory.GetCurrentDirectory() + path;
Has anyone else experienced issues like this when testing with the WCF test client?
Do let me know if it is something to do with the binding/need to see an example of it.
Before I forget, I have <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
within the system.serviceModel
in my app.config
as well.