3

我正在尝试使用 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 中删除该应用程序并手动重新创建它,则该站点可以正常工作。你能告诉我我错过了什么吗?

4

3 回答 3

5

当您运行命令行开关 Convert-ToWebApplication 时,先前的虚拟目录条目仍保留在 applicationhost.config 中。我遇到了同样的错误。

更改您的命令以直接创建应用程序,而不是创建虚拟目录然后对其进行转换。

New-Item IIS:\Sites\DemoSite\Site1 -physicalPath C:\Deployment\application -type Application
于 2013-07-19T20:29:08.260 回答
0

在使用 Web 设置项目将网站部署到 IIS 时,我遇到了同样的问题。设置完成后,网站是虚拟目录而不是应用程序,所以我无法使用 CarlR 的答案。

我最终做的是运行一个 vbs 脚本,然后在安装的提交阶段将一个 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

您可以使用 找到 vdir.name 属性APPCMD list vdir

之后ConvertTo-WebApplication工作并且applicationhost.config不包含virtualdirectory导致此错误的标签。

于 2018-09-29T07:51:27.383 回答
0
  Md $Env:systemdrive\inetpub\Contoso 
  New-WebVirtualDirectory -Site "Default Web Site" -Name "MySite" -PhysicalPath 
  "$Env:systemdrive\inetpub\MySite" ConvertTo-WebApplication -PSPath "IIS:\Sites\Default Web Site\MySite"
于 2022-02-03T07:34:25.433 回答