8

我正在编写一个将网站部署到 IIS 7 的 powershell 脚本。我想使用 powershell 中的 Web-Administration 模块而不是 appcmd 执行以下命令来删除自定义标头。如何在不使用 appcmd 的 powershell 中执行此命令?

appcmd set config /section:httpProtocol /-customHeaders.[name='X-Powered-By']
4

2 回答 2

23

要删除 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'}
于 2013-08-09T17:17:36.837 回答
1

添加一个新的自定义字段,例如。xff-ipx-forwarded-for请求标头中获取远程客户端 IP

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'}
于 2018-06-07T12:47:32.890 回答