Get IIS Web Site Application Name

前端 未结 2 2026
一生所求
一生所求 2021-02-20 03:14

I\'m trying to get the web application name I\'m currently in. (Where my application code is deployed in IIS).

I can get the IIS server name:

string IISs         


        
2条回答
  •  梦毁少年i
    2021-02-20 03:44

    Add the following reference to your application: "c:\windows\system32\inetsrv\Microsoft.web.Administration.dll"

    and use the code below to enumerate web site names and appropriate application names.

    using Microsoft.Web.Administration;
    
    //..
    
    var serverManager = new ServerManager();
    foreach (var site in serverManager.Sites)
    {
        Console.WriteLine("Site: {0}", site.Name);
        foreach (var app in site.Applications)
        {
            Console.WriteLine(app.Path);
        }
    }
    

提交回复
热议问题