キャッシュ可能性を に設定するResponse.Cache
とNoCache
、再度変更する方法はないようです。これは、問題の簡単ですが完全な図です。
protected void Page_Load(object sender, EventArgs e)
{
FieldInfo fi = typeof(HttpCachePolicy).GetField(
"_cacheability",
BindingFlags.NonPublic | BindingFlags.Instance);
// Default value = 6
HttpCacheability first = (HttpCacheability)fi.GetValue(Response.Cache);
// Can change it to Public
Response.Cache.SetCacheability(HttpCacheability.Public);
HttpCacheability second = (HttpCacheability)fi.GetValue(Response.Cache);
// Can change it to Private
Response.Cache.SetCacheability(HttpCacheability.Private);
HttpCacheability third = (HttpCacheability)fi.GetValue(Response.Cache);
// Can change it to NoCache
Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpCacheability fourth = (HttpCacheability)fi.GetValue(Response.Cache);
// Can't go back to Private! Stuck on NoCache
Response.Cache.SetCacheability(HttpCacheability.Private);
HttpCacheability fifth = (HttpCacheability)fi.GetValue(Response.Cache);
}
何か不足していますか?これを行う方法はありますか?
編集:もちろん、Reflectionで設定すればうまくいきますが、あなたが設定したときに何か他のことが起こっているのではないかと心配していHttpCacheability.NoCache
ます。とにかくサポートされた方法。
EDIT2: 同じことが起こるようPrivate
です; もっと制限を加えることしかできませんか?
protected void Page_Load(object sender, EventArgs e)
{
FieldInfo fi = typeof(HttpCachePolicy).GetField(
"_cacheability",
BindingFlags.NonPublic | BindingFlags.Instance);
// Default value = 6
HttpCacheability first = (HttpCacheability)fi.GetValue(Response.Cache);
// Can change it to Private
Response.Cache.SetCacheability(HttpCacheability.Private);
HttpCacheability second = (HttpCacheability)fi.GetValue(Response.Cache);
// Can't change to Public! Stuck on Private
Response.Cache.SetCacheability(HttpCacheability.Public);
HttpCacheability third = (HttpCacheability)fi.GetValue(Response.Cache);
// Can change to NoCache - Can only go more restrictive?
Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpCacheability fourth = (HttpCacheability)fi.GetValue(Response.Cache);
}