0

Anyone know how I might create a script to assign a group of extensions to the framework aspnet_isapi.dll file? I have to do about 20 to each website (about 40 sites) and it is incredibly tedious to do it through the IIS Manager interface.

Thanx.ApplicationExtension Mapping

Stephane Rolland
  • 38,876
  • 35
  • 121
  • 169
Robert Beaubien
  • 3,126
  • 4
  • 22
  • 29

1 Answers1

1

Try this VBScript...I think it will do what you need. Just save it in a .vbs file (change the arrays at the beginning for your websites and extensions) and from a CommandPrompt in the System32 folder run "cscript yourfile.vbs".

Hope it helps (and works :) ) I have IIS7 so couldn't fully test in IIS6. Let me know if you run into problems and I'll try to tweak it.

Oh and Thanks to @Cheeso for some code I "borrowed" from his self-answered 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
Community
  • 1
  • 1
Chris
  • 459
  • 2
  • 3
  • Interesting technique. Seems to work intermittently but haven't figured out what is/isn't working right under what conditions. I am working through them and will edit your post with fixed code and mark it as the answer at that time. Thanx. – Robert Beaubien Aug 16 '11 at 16:16
  • Cool...good luck. You are still trying to do this on IIS 6 boxes right? What weird things have you noticed? On IIS 7 it apparently brings in the maps from the WMI data and merges that info with config file settings. What I noticed that's weird in IIS7 is when you remove it from the management console it doesn't remove it from WMI "database". Oh, and I assume all of the application web.config's have the extensions already mapped in them before what you're trying to do? – Chris Aug 16 '11 at 20:00