windows 使用 New-WebAppPool 时如何设置 .NET Framework 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4229082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I set the .NET Framework Version when using New-WebAppPool?
提问by Matt DiTrolio
I'm looking to see how I can use the IIS PowerShell Cmdlet New-WebAppPoolto specify the version of the .NET Framework to use. Currently, it defaults to v2.0, however I am using MVC, and this will not work because that's a v4.0 feature. We really want each site to have its own Application Pool, and it seems we must create those pools manually due to the inability to configure them via script. Is there any way to automate this?
我希望了解如何使用 IIS PowerShell Cmdlet New-WebAppPool来指定要使用的 .NET Framework 版本。目前,它默认为 v2.0,但是我使用的是 MVC,这将不起作用,因为这是 v4.0 功能。我们真的希望每个站点都有自己的应用程序池,而且由于无法通过脚本配置它们,我们似乎必须手动创建这些池。有没有办法自动化这个?
I'm afraid the answer is going to be "you can't," because the documentationdoesn't appear to offer any parameters for setting it, and Google is turning up squat; it's giving me the impression that only setting up sites in a scripted manner is acceptable, and something about configuring Application Pools is just "not done." I can't possibly imagine why not - if you're automating one major part of the process, why can you not automate the other major part?
恐怕答案是“你不能”,因为文档似乎没有提供任何设置参数,而谷歌正在转向蹲下;它给我的印象是,只有以脚本方式设置站点是可以接受的,而关于配置应用程序池的一些事情只是“没有完成”。我无法想象为什么不 - 如果您要自动化流程的一个主要部分,为什么不能自动化另一个主要部分?
Anyone who might have some insight on how to do this via PowerShell would be helping me out greatly.
任何可能对如何通过 PowerShell 执行此操作有一些见解的人都会极大地帮助我。
回答by Keith Hill
With the WebAdministration module loaded try this on a pool that you've created:
加载 WebAdministration 模块后,在您创建的池上尝试此操作:
Set-ItemProperty IIS:\AppPools\<pool_name> managedRuntimeVersion v4.0
回答by frank tan
Import-Module WebAdministration
#Get all web sites
dir IIS:\Sites | ForEach-Object {
#Go to the app pools root
cd IIS:\AppPools\
if (!(Test-Path $_.Name -pathType container))
{
#Create the app pool and set .net framework version
$appPool = New-Item $_.Name
$appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $IISAppPoolDotNetVersion
#Go to the web sites root
cd IIS:\Sites\
$iisApp = Get-Item $_.Name
$iisApp | Set-ItemProperty -Name "applicationPool" -Value $_.Name
}
else {
$dotNetVersion = (Get-ItemProperty $_.Name managedRuntimeVersion).Value
if ($dotNetVersion -ne $IISAppPoolDotNetVersion){
#Get the app pool and set .net framework version
$appPool = Get-Item $_.Name
$appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $IISAppPoolDotNetVersion
}
}
}
You can download detail script from how to set the IIS Application Pool to specify version of the .NET Framework
您可以从如何设置 IIS 应用程序池中下载详细脚本以指定 .NET Framework 的版本