I have IIS 7.0 installed on and there is a .net application with a .svc service there.
I would like to point a file in the virtual directory pointed by the application (please note that I converted my virtual dir in an application).
However, when I try to open a file, using a general api call in the .net-verse, and do not specify a root (complete) path but relative, I end up in the error when a resource is not found.
How can I obtain the physical path of my app?
Note that this is a web application. It cannot use the Request
object because it needs to make this call from the web service, hosted by my app.
Virtual directories and applications are now separate objects, and they exist in a hierarchical relationship in the IIS configuration schema. Briefly, a site contains one or more applications, an application contains one or more virtual directories, and a virtual directory maps to a physical directory on a computer.
A virtual directory is a directory name that you specify in IIS and map to physical directory on a local server's hard drive or a directory on another server (remote server). You can use Internet Information Services Manager to create a virtual directory for an ASP.NET Web application that is hosted in IIS.
An application in Internet Information Services (IIS) 7 or later is a grouping of files that delivers content or provides services over protocols, such as HTTP. When you create an application in IIS 7 and later, the application's path becomes part of the site's URL.
try this might help to resolve your issue
string apPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
or
string apPath = System.Web.Hosting.HostingEnvironment.MapPath("~/folder/file");
If you're using a console application project template or any other template other than Web application then you have to add a reference to System.Web.
You will then be able to refer to the System.Web.Hosting namespace.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With