ASP.NET Web サイトで静的コンテンツをキャッシュするためのルールを IIS7 で設定したいと思います。
<clientCache />
以下の記事では、 の要素を使用してこれを行う方法が詳しく説明されていますweb.config
。
クライアント キャッシュ
<clientCache>
(IIS.NET)
IIS の静的コンテンツに Expires または Cache Control Header を追加する (Stack Overflow)
ただし、この設定はすべての静的コンテンツにグローバルに適用されるようです。特定のディレクトリまたは拡張機能に対してのみこれを行う方法はありますか?
たとえば、別々のキャッシュ設定が必要な 2 つのディレクトリがあるとします。
/static/images
/content/pdfs
拡張子とフォルダ パスに基づいてキャッシュ ヘッダー ( max-age
、など)を送信するためのルールを設定することは可能ですか?expires
Please note, I must be able to do this via web.config
because I don't have access to the IIS console.
ベストアンサー1
You can set specific cache-headers for a whole folder in either your root web.config
:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- Note the use of the 'location' tag to specify which
folder this applies to-->
<location path="images">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
</staticContent>
</system.webServer>
</location>
</configuration>
Or you can specify these in a web.config
file in the content folder:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
</staticContent>
</system.webServer>
</configuration>
I'm not aware of a built in mechanism to target specific file types.