【问题标题】:Script Application Extension assignments脚本应用程序扩展分配
【发布时间】:2011-08-03 04:06:10
【问题描述】:

有人知道我如何创建一个脚本来为框架 aspnet_isapi.dll 文件分配一组扩展吗?我必须对每个网站执行大约 20 个操作(大约 40 个站点),并且通过 IIS 管理器界面执行此操作非常繁琐。

谢谢。

【问题讨论】:

    标签: .net asp.net iis-6


    【解决方案1】:

    试试这个 VBScript...我认为它会满足您的需求。只需将其保存在 .vbs 文件中(更改网站开头的数组和扩展名),然后从 System32 文件夹中的命令提示符运行“cscript yourfile.vbs”。

    希望它有所帮助(并且有效:))我有 IIS7,因此无法在 IIS6 中进行完全测试。如果您遇到问题,请告诉我,我会尝试调整它。

    哦,感谢 @Cheeso 提供的一些代码,我从他的自我回答 question 中“借来”了一些代码。

    Dim arrExtensions(2)
    arrExtensions(0) = ".tst1"
    arrExtensions(1) = ".tst2"
    arrExtensions(2) = ".tst3"
    
    Dim arrSites(1)
    arrSites(0) = "Default Web Site"
    arrSites(1) = "Test"
    
    Dim iis
    iis = GetObject("winmgmts://localhost/root/MicrosoftIISv2")
    
    For s = 0 To ubound(arrSites)
        ' Get the settings for this web site '
        iisSettings = iis.ExecQuery("SELECT * FROM IIsWebServerSetting WHERE ServerComment = '" & arrSites(s) & "'")
    
        For e = 0 To ubound(arrExtensions)
            ReDim newMaps(0)
            ' two passes '
            For t = 0 To 1
                Dim c
                c = 0
                For Each item In iisSettings
                    ' in pass 1, count them. '
                    ' in pass 2, copy them. '
                    For i = 0 To Ubound(item.ScriptMaps)
                        If UCase(item.ScriptMaps(i).Extensions) <> ucase(arrExtensions(e)) Then
                            If t = 1 Then
                                newMaps(c) = item.ScriptMaps(i)
                            End If
                            c = c + 1
                        End If
                    Next
    
                    If t = 0 Then
                        ReDim Preserve newMaps(c)
                    Else
                        newMaps(c) = iis.get("ScriptMap").SpawnInstance_()
                        newMaps(c).Extensions = arrExtensions(e)
                        newMaps(c).ScriptProcessor = "%Windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
                        newMaps(c).Flags = "1"
                        newMaps(c).IncludedVerbs = "ALL"
                        item.ScriptMaps = newMaps
                        item.Put_()
                    End If
                Next
    
            Next
    
        Next
    Next
    
    iisSettings = Nothing
    iis = Nothing
    

    【讨论】:

    • 有趣的技术。似乎间歇性地工作,但还没有弄清楚在什么条件下什么是/不工作的。我正在处理它们,并将使用固定代码编辑您的帖子并将其标记为当时的答案。谢谢。
    • 酷...祝你好运。您仍在尝试在 IIS 6 机器上执行此操作,对吗?你注意到了什么奇怪的事情?在 IIS 7 上,它显然会从 WMI 数据中引入地图,并将该信息与配置文件设置合并。我注意到在 IIS7 中很奇怪的是,当您将其从管理控制台中删除时,它不会将其从 WMI“数据库”中删除。哦,我假设所有应用程序 web.config 的扩展已经在您尝试执行之前映射到其中?
    猜你喜欢
    • 2017-06-01
    • 1970-01-01
    • 2012-02-10
    • 2021-08-07
    • 2019-07-31
    • 2014-05-30
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多