Skip to content

Instantly share code, notes, and snippets.

@rriifftt
Created October 27, 2015 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rriifftt/379f1e66a5518610a6bd to your computer and use it in GitHub Desktop.
Save rriifftt/379f1e66a5518610a6bd to your computer and use it in GitHub Desktop.
powershell で X-AspNet-Version ヘッダを削除する ref: http://qiita.com/satoshi_iwashita/items/5d2a3bf91a79096955ed
<system.web>
<httpRuntime enableVersionHeader="false" />
</system.web>
c:\windows\system32\inetsrv\appcmd.exe set config -section:system.web/httpRuntime -enableVersionHeader:false /commit:webroot /clr:4
<system.webServer>
<rewrite>
<allowedServerVariables>
<add name="RESPONSE_X-ASPNET-VERSION" />
</allowedServerVariables>
<outboundRules>
<rule name="RESPONSE_X-ASPNET-VERSION">
<match serverVariable="RESPONSE_X-ASPNET-VERSION" pattern=".+" />
<action type="Rewrite" />
</rule>
</outboundRules>
</rewrite>
</system.webServer>
# add allowedServerVariables
$asv = Get-WebConfigurationProperty `
-filter "//rewrite/allowedServerVariables/add"`
-name name
if ($asv -eq $null)
{
Add-WebConfigurationProperty `
-Filter "//rewrite/allowedServerVariables" `
-PSPath "IIS:\" `
-Name "Collection" `
-Value @{name="RESPONSE_X-ASPNET-VERSION"}
}
# add rule
$rule = Get-WebConfigurationProperty `
-filter "//rewrite/outboundRules/rule[@name='REMOVE_X-ASPNET-VERSION']/match"`
-name serverVariable
if ($rule -eq $null)
{
Add-WebConfigurationProperty `
-Filter "//rewrite/outboundRules" `
-PSPath "IIS:\" `
-Name "Collection" `
-Value @{name="REMOVE_X-ASPNET-VERSION"}
Set-WebConfiguration `
-Filter "//rewrite/outboundRules/rule[@name='REMOVE_X-ASPNET-VERSION']/match" `
-PSPath "IIS:\" `
-Value @{serverVariable="RESPONSE_X-ASPNET-VERSION";pattern=".+"}
Set-WebConfiguration `
-Filter "//rewrite/outboundRules/rule[@name='REMOVE_X-ASPNET-VERSION']/action" `
-PSPath "IIS:\" `
-Value @{type="Rewrite"}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment