Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Physical Path from Microsoft.Web.Administration and path relative to it's root

Tags:

.net

iis-7

I want to find the physical path within an IIS website, of a path relative to the root of the website, using Microsoft.Web.Administration .NET assembly.

There doesn't seem to a single method to do this, but I am wondering - is the following procedure the best way?:

  1. Get the Microsoft.Web.Administration.Site object
  2. Find the application with the longest path which matches the beginning of the path relative to the root
  3. Strip the application path from the beginning of the path relative to the root, giving the path relative to the application
  4. Find the virtual directory within this application with the longest path which matches the beginning of the path relative to the application
  5. Strip the application path from the beginning of the path relative to the application, giving the path relative to the virtual directory
  6. Append the path relative to the virtual directory (swapping / for ) to the physical path of the virtual directory to give the physical path we want

Lee

like image 212
Lee Atkinson Avatar asked Dec 02 '10 11:12

Lee Atkinson


1 Answers

I found the following code to get the path

ServerManager sm = new ServerManager();
sm.Sites["Default Web Site"].Applications["/"].VirtualDirectories["/"].PhysicalPath;

http://forums.iis.net/t/1146686.aspx/1

like image 174
Jonathan Mc Namee Avatar answered Oct 09 '22 13:10

Jonathan Mc Namee