Get Id of a website in IIS-7 and above

前端 未结 1 1875
情书的邮戳
情书的邮戳 2021-01-16 17:30

I am able to get physical path for any website hosted in IIS-7(C:\\Windows\\System32\\inetsrv\\config \\applicationHost.config) programmatically (C#) by passing ID as a para

1条回答
  •  有刺的猬
    2021-01-16 18:18

    Have you tried to use the new ServerManager object (available for IIS 7.0 and up, through Microsoft.Web.Administration)?

    Please try using the following snippet:

    using (ServerManager serverManager = new ServerManager()) { 
    
    var sites = serverManager.Sites; 
    foreach (Site site in sites) 
    { 
      Console.WriteLine(site.Id); 
    }
    

    To obtain the ID of one site in particular, LINQ works like a charm.

    0 讨论(0)
提交回复
热议问题