Find the physical path from Microsoft.Web.Administration and the root path to it

I want to find the physical path on the IIS website, the path to the root of the website using the Microsoft.Web.Administration.NET assembly.

There is no single method for this, but I wonder - this is the following procedure:

  • Get Microsoft.Web.Administration.Site Object
  • Find the application using the longest path that matches the beginning of the path relative to the root
  • Separate the application path from the beginning of the path relative to the root, path relative to the application
  • Find the virtual directory inside this application with the longest path that matches the beginning of the path relative to the application
  • Separate the application path from the very beginning of the path relative to the application giving the path relative to the virtual directory
  • Add the path relative to the virtual directory (swapping / for) to the physical path of the virtual directory to indicate the physical path we want

Lee

+3
source share
3 answers

, . , , , :
1) , ( , (ip, ..)).
2) , URL-.
3) VirtualDirectory , URL-.
4) Path.Combine(vdir.PhysicalPath, " URL- / \" )

. , URL- ( , MVC Rewriting), .

+3

,

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

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

+3

To list the entire virtual and physical path from the server:

Dim stringIIS As String = String.Empty
Dim serverName As String = "MACHINE_NAME"
Dim sm1 As New ServerManager()

        Using sm As Microsoft.Web.Administration.ServerManager = Microsoft.Web.Administration.ServerManager.OpenRemote(serverName)

            Dim counter As Integer = 1

            For Each Site As Microsoft.Web.Administration.Site In sm.Sites

                stringIIS = "Site: " & Site.Name & (vbNewLine)

                For Each app As Microsoft.Web.Administration.Application In sm.Sites(Site.Name).Applications
                    stringIIS = stringIIS & "        Physical Path: " & (vbTab & sm1.Sites(Site.Name).Applications("/").VirtualDirectories("/").PhysicalPath().ToString() & vbNewLine)

                    For Each virtDir As Microsoft.Web.Administration.VirtualDirectory In app.VirtualDirectories
                        stringIIS = stringIIS & "        Virtual Path: " & (vbTab & app.Path & vbNewLine)
                        stringIIS = stringIIS & vbNewLine
                    Next
                Next

                counter += 1

            Next

            iis.Text = stringIIS
            iis.Visible = True
        End Using
+1
source

Source: https://habr.com/ru/post/1778093/


All Articles