PowerShellでIISのHTTP応答ヘッダー(共通)を変更
6004 ワード
PowerShellを活用すれば、IISのあらゆる操作がコマンドで実行可能です。
環境構築の自動化・効率化に是非お役立てください。
今回はクライアントキャッシュの設定変更。
IISを立ち上げて、該当のサイトを選択して、「HTTP応答ヘッダー」を選択して、右メニューの「共通ヘッダーの設定」をクリックして…なんて手順書とはもうお別れです。
おまじない
#管理者権限で実行
Start-Process powershell.exe -Verb runas
#サイト名
$siteName = 'Default Web Site'
クライアントキャッシュの削除設定
#管理者権限で実行
Start-Process powershell.exe -Verb runas
#サイト名
$siteName = 'Default Web Site'
設定しない(「期限切れのWebコンテンツ」のチェックを外す)
Set-WebConfigurationProperty `
-PSPath "MACHINE/WEBROOT/APPHOST/$siteName" `
-Name . -filter "system.webServer/staticContent/clientCache" `
-Value (@{cacheControlMode="NoControl";})
即時
Set-WebConfigurationProperty `
-PSPath "MACHINE/WEBROOT/APPHOST/$siteName" `
-Name . -filter "system.webServer/staticContent/clientCache" `
-Value (@{cacheControlMode="DisableCache";})
失効までの期間
Set-WebConfigurationProperty `
-PSPath "MACHINE/WEBROOT/APPHOST/$siteName" `
-Name . -filter "system.webServer/staticContent/clientCache" `
-Value (@{cacheControlMode="UseMaxAge";cacheControlMaxAge="02:00:00";})
有効期限
Set-WebConfigurationProperty `
-PSPath "MACHINE/WEBROOT/APPHOST/$siteName" `
-Name . -filter "system.webServer/staticContent/clientCache" `
-Value (@{cacheControlMode="UseExpires";httpExpires="Tue, 19 Jan 2038 03:14:07 GMT";})
正しく設定が反映されたか、IISの画面から(一度は)確認しておきましょう。
参考:公式マニュアル
https://docs.microsoft.com/en-us/iis/configuration/system.webserver/staticcontent/clientcache
Author And Source
この問題について(PowerShellでIISのHTTP応答ヘッダー(共通)を変更), 我々は、より多くの情報をここで見つけました https://qiita.com/dntnd/items/db22a9e09f38f40a542d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .