我正在尝试使用powershell将.NET 4应用程序部署到虚拟目录。我使用以下代码;
Import-Module webadministration
New-Item IIS:\AppPools\MainAppPool
Set-ItemProperty IIS:\AppPools\MainAppPool managedRuntimeVersion v4.0
New-Item IIS:\AppPools\Site1AppPool
Set-ItemProperty IIS:\AppPools\Site1AppPool managedRuntimeVersion v4.0
New-Item IIS:\Sites\DemoSite -physicalPath C:\DemoSite -bindings @{protocol="http";bindingInformation=":82:"}
Set-ItemProperty IIS:\Sites\DemoSite -name applicationPool -value DemoAppPool
New-Item IIS:\Sites\DemoSite\Site1 -physicalPath C:\Deployment\application -type VirtualDirectory
ConvertTo-WebApplication IIS:\Sites\DemoSite\Site1
Set-ItemProperty IIS:\sites\DemoSite\Site1 -name applicationPool -value Site1AppPool
当我运行它时,它似乎工作正常,但在运行网站时,我收到以下错误;
Configuration Error
**Description**: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
**Parser Error Message**: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
Source Error:
Line 13: ASP.NET to identify an incoming user.
Line 14: -->
Line 15: <authentication mode="Windows" />
Line 16: <!--
Line 17: The <customErrors> section enables configuration
如果我然后在IIS中删除该应用程序并手动重新创建它,该网站工作正常。你能告诉我我错过了什么吗?
答案 0 :(得分:5)
运行命令行开关Convert-ToWebApplication时,先前的虚拟目录条目仍保留在applicationhost.config中。我遇到了同样的错误。
更改命令直接创建应用程序,而不是创建虚拟目录然后转换它。
New-Item IIS:\Sites\DemoSite\Site1 -physicalPath C:\Deployment\application -type Application
答案 1 :(得分:0)
在使用Web安装项目将网站部署到IIS时,我遇到了同样的问题。 设置完成后,网站是虚拟目录,而不是应用程序,因此我无法使用CarlR的答案。
我最终要做的是运行vbs脚本,然后在安装的Commit阶段将powershell脚本转换为exe。
Dim objShell, strPath, strVdir
Set objShell = CreateObject ("WScript.Shell")
strPath = """%systemroot%\system32\inetsrv\APPCMD"""
strVdir = "delete vdir /vdir.name:""Default Web Site/PathToVirtualDirectory"""
objShell.Run strPath & strVdir
您可以使用APPCMD list vdir
找到vdir.name属性。
此后,ConvertTo-WebApplication
起作用并且applicationhost.config
不包含导致此错误的virtualdirectory
标记。