Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 需要将Access Control Allow-*标题添加到web.config_Powershell_Iis_Octopus Deploy - Fatal编程技术网

Powershell 需要将Access Control Allow-*标题添加到web.config

Powershell 需要将Access Control Allow-*标题添加到web.config,powershell,iis,octopus-deploy,Powershell,Iis,Octopus Deploy,我正在尝试使用powershell脚本将以下内容添加到我的web.config中 <system.webServer> <httpProtocol> <customHeaders> <clear /> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Headers

我正在尝试使用powershell脚本将以下内容添加到我的web.config中

<system.webServer>
  <httpProtocol>
    <customHeaders>
      <clear />
      <add name="Access-Control-Allow-Origin" value="*" />
      <add name="Access-Control-Allow-Headers" value="Content-Type" />
      <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
    </customHeaders>
  </httpProtocol>
当这是执行我得到以下结果在八达通

警告:目标配置对象 'system.webServer/httpProtocol/customHeaders/Access-Control-Allow-Origin不是 在路径“MACHINE/WEBROOT/APPHOST/sub.mysite.com”中找到


该值不会被添加。我已经导入了WebAdministration模块,其他大部分设置都可以正常工作

我认为您的XPath表达式与您试图操作的节点不匹配。试试这个:

Add-WebConfigurationProperty -PSPath $sitePath `
  -Filter 'system.webServer/httpProtocol/customHeaders/add[@name="Access-Control-Allow-Origin"]' `
  -Name 'value' -Value '*' -Force

设法用以下方法解决问题

Add-WebConfigurationProperty //system.webServer/httpProtocol/customHeaders  "IIS:\sites\test.test1.com" -AtIndex 0 -Name collection -Value @{name='Access-Control-Allow-Origin';value='*'}
Add-WebConfigurationProperty //system.webServer/httpProtocol/customHeaders  "IIS:\sites\test.test1.com" -AtIndex 0 -Name collection -Value @{name='Access-Control-Allow-Headers';value='Content-Type'}
Add-WebConfigurationProperty //system.webServer/httpProtocol/customHeaders  "IIS:\sites\test.test1.com" -AtIndex 0 -Name collection -Value @{name='Access-Control-Allow-Methods';value='GET, OPTIONS'}

希望这对以后的人有所帮助,在这方面浪费了大量时间。

Hi,尝试了这一点,不再收到警告,但是web.config中仍然没有设置该属性。
Add-WebConfigurationProperty //system.webServer/httpProtocol/customHeaders  "IIS:\sites\test.test1.com" -AtIndex 0 -Name collection -Value @{name='Access-Control-Allow-Origin';value='*'}
Add-WebConfigurationProperty //system.webServer/httpProtocol/customHeaders  "IIS:\sites\test.test1.com" -AtIndex 0 -Name collection -Value @{name='Access-Control-Allow-Headers';value='Content-Type'}
Add-WebConfigurationProperty //system.webServer/httpProtocol/customHeaders  "IIS:\sites\test.test1.com" -AtIndex 0 -Name collection -Value @{name='Access-Control-Allow-Methods';value='GET, OPTIONS'}