Output Caching with IIS7 - How To for a dynamic aspx page?
- by Lieven Cardoen
I have a RetrieveBlob.aspx that gets some query string variables and returns an asset. Eeach url corresponds to a unique asset.
In the RetrieveBlob.aspx a Cache Profile is set. In Web.Config the profile looks like (under system.web tag):
<caching>
<outputCache enableOutputCache="true" />
<outputCacheSettings>
<outputCacheProfiles>
<add duration="14800" enabled="true" varyByParam="*"
name="AssetCacheProfile" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
Ok, this works fine. When I put a breakpoint in the code behind of RetrieveBlob.aspx, it gets triggered the first time, and all the other times not.
Now, I throw away the Cache Profile and instead I'm having this in my Web.Config under System.WebServer:
<caching>
<profiles>
<add extension=".swf" policy="CacheForTimePeriod"
kernelCachePolicy="CacheForTimePeriod" duration="00:08:00" />
<add extension=".flv" policy="CacheForTimePeriod"
kernelCachePolicy="CacheForTimePeriod" duration="00:08:00" />
<add extension=".gif" policy="CacheForTimePeriod"
kernelCachePolicy="CacheForTimePeriod" duration="00:08:00" />
<add extension=".png" policy="CacheForTimePeriod"
kernelCachePolicy="CacheForTimePeriod" duration="00:08:00" />
<add extension=".mp3" policy="CacheForTimePeriod"
kernelCachePolicy="CacheForTimePeriod" duration="00:08:00" />
<add extension=".jpeg" policy="CacheForTimePeriod"
kernelCachePolicy="CacheForTimePeriod" duration="00:08:00" />
<add extension=".jpg" policy="CacheForTimePeriod"
kernelCachePolicy="CacheForTimePeriod" duration="00:08:00" />
</profiles>
</caching>
Now the caching doesn't work anymore. What am I doing wrong? Is it possible to configure under Caching tag of System.WebServer a Caching Profile for a Dynamic aspx page?
I already tried adding something like this:
<add extension="RetrieveBlob.aspx" policy="CacheForTimePeriod"
kernelCachePolicy="CacheForTimePeriod" duration="00:00:30"
varyByQueryString="assetId, assetFileId" />
But it doesn't work.
An example of an url is:
http://{server}/{application}/trunk/RetrieveBlob.aspx?assetId=31809&assetFileId=11829