In my IIS server I have a Virtual Directory ("docPath") which is mapped with a physical folder of my machine.
I have a Window Service and from this service I need to get the Physical path of Virtual directory (created on IIS) i.e. "docPath".
Since this is Windows service so I do not have HTTPContext object and I cannot use the HttpContext.Current.Server.MapPath("/docPath");
This is what I've tried so far:
I have tried to use the ServerManager from Microsoft.Web.Administration.
ServerManager serverManager = new ServerManager();
Site site = serverManager.Sites.FirstOrDefault(s => s.Name == "Default Web Site");
Application myApp = site.Applications["/docPath"];
But in Sites only web application created on IIS server are coming and not Virtual directories.
Also, System.Web.Hosting.HostingEnvironment.MapPath is also not working.
Could anybody let me know how can I get physical path of a Virtual Directory in Windows Service?
MapPath(). Then the service can read that response. - Remy LebeauSystem.Web.Hosting.HostingEnvironment.MapPath. - JanneP