如何使用asphell脚本为asp.net 4.0进行IIS预热?

时间:2011-06-14 13:44:06

标签: iis powershell

任何人都可以告诉我如何使用asphell脚本编写IIS以使用asp.net 4.0预热机制吗?

我已经创建了这个powershell脚本,但它似乎没有在applicationHost.config文件中写入任何内容: (尝试从此处实施第3步,但使用Powershell:http://weblogs.asp.net/gunnarpeipman/archive/2010/01/31/asp-net-4-0-how-to-use-application-warm-up-class.aspx

Import-Module WebAdministration

$SiteName="Default Web Site"
$ApplicationName=“WebOne“

Add-WebConfiguration "system.applicationHost/sites/site[@name='Default Web Site']/application[@path='WebOne']" -Value @{serviceAutoStartEnabled="true";serviceAutoStartProvider="PreWarmMyCache"} -PSPath IIS:\Sites\$SiteName\$ApplicationName -Location $SiteName/$ApplicationName

我正在尝试添加这两(2)个属性( serviceAutoStartEnabled="true" and serviceAutoStartProvider="PreWarmMyCache"):

e.g:

<application path="/" serviceAutoStartEnabled="true" serviceAutoStartProvider="PreWarmMyCache" />:

到我目前的申请路径:

<sites>
     <site name="Default Web Site" id="1">
                <application path="/WebOne" applicationPool="ASP.NET v4.0">
                    <virtualDirectory path="/" physicalPath="C:\NetProjects\WebOne" />
                </application>         
     </site>
</sites>

我还需要PowerShell脚本: (从这里开始的第4步,但使用Powershell:http://weblogs.asp.net/gunnarpeipman/archive/2010/01/31/asp-net-4-0-how-to-use-application-warm-up-class.aspx

<serviceAutoStartProviders>
     <add name="PreWarmMyCache" type="PreWarmCache, MyAssembly" />
</serviceAutoStartProviders>

任何帮助都会受到极大的关注.-

我已经在下面编写了这些东西,但是我需要上面的东西(serviceAutoStartEnabled =“true”和serviceAutoStartProvider =“PreWarmMyCache”),我提到过.-

#Load IIS Modules
Import-Module WebAdministration   

if (Test-Path IIS:\AppPools\SosSWarmUpWorkerProcess)
{
    #Let's delete the entry if it's already there ( while deploying between versions )
    Remove-Item IIS:\AppPools\SosSWarmUpWorkerProcess -Force -Recurse
}

$myNewPool = New-Item IIS:\AppPools\SosSWarmUpWorkerProcess  
$myNewPool.managedRuntimeVersion = "4.0"
$myNewPool.startMode="AlwaysRunning"

$myNewPool | Set-Item

1 个答案:

答案 0 :(得分:0)

我无法在New-Item或New-WebApplication中找到允许您为新应用程序设置AutoStart的参数。但是,您可以在创建应用程序后设置属性:

$vdirPath = Join-Path "IIS:\Sites" (Join-Path $iisSite $virtualDirectoryName)
New-Item $vdirPath -physicalPath $webSitePath -type Application 
Set-ItemProperty $vdirPath -name serviceAutoStartEnabled -value "true"
Set-ItemProperty $vdirPath -name serviceAutoStartProvider -value "PreWarmMyCache"