How to use ServerManager to read IIS sites, not IIS express, from class library OR how do elevated processes handle class libraries?

前端 未结 4 573
说谎
说谎 2020-12-25 10:45

I have some utility methods that use Microsoft.Web.Administration.ServerManager that I\'ve been having some issues with. Use the following dead simple code for

4条回答
  •  鱼传尺愫
    2020-12-25 11:25

    Your question helped me find the answer for PowerShell, so if the Internet is searching for how to do that:

    $assembly = [System.Reflection.Assembly]::LoadFrom("$env:systemroot\system32\inetsrv\Microsoft.Web.Administration.dll")
    
    # load IIS express
    $iis = new-object Microsoft.Web.Administration.ServerManager 
    $iis.Sites
    
    # load IIS proper
    $iis = new-object Microsoft.Web.Administration.ServerManager "$env:systemroot\system32\inetsrv\config\applicationhost.config"  
    $iis.Sites
    

提交回复
热议问题