【问题标题】:IIS auto-generated webpage listing all websites being hostedIIS 自动生成的网页列出了所有托管的网站
【发布时间】:2018-01-23 20:34:08
【问题描述】:

基本上就是标题所说的。是否有 IIS 的/插件功能允许在单个网页中显示一个列表,其中包含指向 IIS 中托管的网站的链接?

我知道我可以通过以下方式从命令行获取所述列表:

%windir%\system32\inetsrv\appcmd list site > c:\sites.xls

这将创建一个 Excel 电子表格,其中包含 IIS 中的站点列表以及每个站点的站点相关信息。

但是我将不得不解析 CSV 文件并将其转换为 html。这会起作用,但如果已经有完全相同的功能或插件,我宁愿完全避开它。

【问题讨论】:

    标签: iis appcmd


    【解决方案1】:

    您可以为此使用 Powershell:您可以循环访问 IIS 站点、虚拟目录、Web 应用程序并动态构建一个简单的 html 页面。

    这是一个简单的脚本,它创建一个 html 文件,其中包含指向每个虚拟目录或 Web 应用程序的链接列表。这只是一个基本脚本,您可以自定义它并添加更多细节:

    #Import WebAdministration to manage IIS contents
    Import-Module WebAdministration
    
    #define a variable that will hold your html code
    $html = "<html>`n<body>"
    
    #define the root path of your sites (in this example localhost)
    $rootFolder = "http://localhost"
    
    $Websites = Get-ChildItem IIS:\Sites 
    
    #loop on all websites inside IIS
    foreach($Site in $Websites)
    {
        $VDirs = Get-WebVirtualDirectory -Site $Site.name
        $WebApps = Get-WebApplication -Site $Site.name
    
        #loop on all virtual directories    
        foreach ($vdir in $VDirs )
        {
        $html += "`n<a href='" + $rootFolder + $vdir.path +"'>" + $vdir.path + "</a><br/>"
        }
        #loop on all web applications
        foreach ($WebApp in $WebApps)
        { 
        $html += "`n<a href='" + $rootFolder + $WebApp.path +"'>" + $WebApp.path + "</a><br/>"
        }
    }
    #add final tags to html
    $html += "`n</body>`n</html>"
    
    #write html code to file
    $html >> "d:\sites.html" 
    

    以这种 IIS 结构为例:

    你会得到以下html:

    <html>
    <body>
    <a href='http://localhost/vd'>/vd</a><br/>
    <a href='http://localhost/test'>/test</a><br/>
    <a href='http://localhost/test2'>/test2</a><br/>
    </body>
    </html>
    

    呈现如下:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-16
      • 2017-05-06
      相关资源
      最近更新 更多