我正在编写一个将网站部署到IIS 7的PowerShell脚本。我想使用PowerShell中的Web管理模块而不是appcmd执行以下命令来删除自定义标头。如何在PowerShell中执行此命令而不使用appcmd?
appcmd set config /section:httpProtocol /-customHeaders.[name='X-Powered-By']
答案 0 :(得分:19)
删除iis级别的标题:
Remove-WebConfigurationProperty -PSPath MACHINE/WEBROOT/APPHOST
-Filter system.webServer/httpProtocol/customHeaders
-Name .
-AtElement @{name='X-Powered-By'}
对于特定网站:
Remove-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST/Default Web Site'
-Filter system.webServer/httpProtocol/customHeaders
-Name .
-AtElement @{name='X-Powered-By'}
答案 1 :(得分:0)
xff-ip
从x-forwarded-for
请求标头Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/siteDefaults/logFile/customFields" -name "." -value @{logFieldName='xff-ip';sourceName='X-FORWARDED-FOR';sourceType='RequestHeader'}
或针对特定网站:
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='My Super Site']/logFile/customFields" -name "." -value @{logFieldName='xff-ip';sourceName='X-FORWARDED-FOR';sourceType='RequestHeader'}
xff-ip
Remove-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/siteDefaults/logFile/customFields" -name "." -AtElement @{logFieldName='xff-ip'}
或仅从您的网站
Remove-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='My Super Site']/logFile/customFields" -name "." -AtElement @{logFieldName='xff-ip'}