Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting IIS Application filesystem path

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.

like image 241
Andry Avatar asked Jun 13 '11 19:06

Andry


People also ask

What is the difference between virtual directory and application in IIS?

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.

Why we use virtual directory in IIS?

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.

What are IIS applications?

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.


2 Answers

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");
like image 128
Pranay Rana Avatar answered Oct 12 '22 20:10

Pranay Rana


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!

like image 43
raring sunny Avatar answered Oct 12 '22 20:10

raring sunny