How do I remove IIS custom header using Powershell?

前端 未结 2 699
感动是毒
感动是毒 2021-01-05 08:58

I am writing a powershell script that deploys a website to IIS 7. I would like to do the following command to remove a custom header using the Web-Administration module in

2条回答
  •  抹茶落季
    2021-01-05 09:17

    Adding a new custom field eg. xff-ip to have remote client ip from x-forwarded-for request header

    Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/sites/siteDefaults/logFile/customFields" -name "." -value @{logFieldName='xff-ip';sourceName='X-FORWARDED-FOR';sourceType='RequestHeader'}
    

    Or for a specific site:

    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'}
    

    Removing your added custom logging field eg.xff-ip

    Remove-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/siteDefaults/logFile/customFields" -name "."  -AtElement @{logFieldName='xff-ip'}
    

    Or from your site only

    Remove-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='My Super Site']/logFile/customFields"  -name "." -AtElement @{logFieldName='xff-ip'}
    

提交回复
热议问题