VBScript / IIS-如何为特定网站自动设置ASP.NET版本

时间:2020-03-05 18:41:45  来源:igfitidea点击:

我需要编写脚本在IIS 6.0上创建应用程序池和网站。我已经能够使用adsutil.vbs和iisweb.vbs创建这些文件,但是不知道如何将刚刚创建的站点的ASP.NET版本设置为2.0.50727.0。

理想情况下,我想adsutil.vbs更新配置数据库。我该怎么做呢?

解决方案

回答

我在Diablo Pup的博客上找到了以下脚本。它使用ADSI自动化。

'******************************************************************************************
' Name: SetASPDotNetVersion
' Description: Set the script mappings for the specified ASP.NET version
' Inputs: objIIS, strNewVersion
'******************************************************************************************
Sub SetASPDotNetVersion(objIIS, strNewVersion)
 Dim i, ScriptMaps, arrVersions(2), thisVersion, thisScriptMap
 Dim strSearchText, strReplaceText

 Select Case Trim(LCase(strNewVersion))
  Case "1.1"
   strReplaceText = "v1.1.4322"
  Case "2.0"
   strReplaceText = "v2.0.50727"
  Case Else
   wscript.echo "WARNING: Non-supported ASP.NET version specified!"
   Exit Sub
 End Select

 ScriptMaps = objIIS.ScriptMaps
 arrVersions(0) = "v1.1.4322"
 arrVersions(1) = "v2.0.50727"
 'Loop through all three potential old values
 For Each thisVersion in arrVersions
  'Loop through all the mappings
  For thisScriptMap = LBound(ScriptMaps) to UBound(ScriptMaps)
   'Replace the old with the new 
   ScriptMaps(thisScriptMap) = Replace(ScriptMaps(thisScriptMap), thisVersion, strReplaceText)
  Next
 Next 

 objIIS.ScriptMaps = ScriptMaps
 objIIS.SetInfo
 wscript.echo "<-------Set ASP.NET version to " & strNewVersion & " successfully.------->"
End Sub

回答

@Chris以ADSI方式击败了我

我们可以使用aspnet_regiis.exe工具执行此操作。在计算机上每个版本的ASP.NET都有这些工具之一。我们可以掏出-

这将配置ASP.NET 1.1

%windir%\microsoft.net\framework\v1.1.4322\aspnet_regiis -s W3SVC/[iisnumber]/ROOT

这将配置ASP.NET 2.0

%windir%\microsoft.net\framework\v2.0.50727\aspnet_regiis -s W3SVC/[iisnumber]/ROOT

我们可能已经知道这一点,但是如果计算机上有多个1.1和2.0站点,只需记住将要更改ASP.NET版本的网站切换到兼容的应用程序池即可。 ASP.NET 1.1和2.0站点不在同一应用程序池中混合使用。