6

私はこのアクションメソッドを持っています:

    [OutputCache(Duration = 2, 
                 Location = OutputCacheLocation.Any, 
                 VaryByHeader = "Accept-Charset")]
    public ActionResult Index()
    {
        return View();
    }

そして、生成された応答は次のとおりです。

Cache-Control:public, max-age=2
Content-Length:5164
Content-Type:text/html; charset=utf-8
Date:Wed, 28 Sep 2011 16:30:33 GMT
Expires:Wed, 28 Sep 2011 16:30:35 GMT
Last-Modified:Wed, 28 Sep 2011 16:30:33 GMT
Server:Microsoft-IIS/7.5
Vary:*
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0
X-Powered-By:ASP.NET

Varyヘッダーに代わりにアスタリスクが表示されるのはなぜAccept-Charsetですか?

OutputCacheAttribute応答に影響を与えますが、実際には、ヘッダーExpiresCache-Control:max-age=nヘッダーはDuration引数に依存し、 Cache-Control:public//は引数に依存しprivateます。no-cacheLocation

OutputCacheAttribute何が起こっているかを確認するためのラッパーを作成しました。

public class CustomOutputCacheAttribute:OutputCacheAttribute
{
    public override void OnResultExecuted(ResultExecutedContext filterContext)
    {
        base.OnResultExecuted(filterContext);

        Dictionary<String, String> headers = new Dictionary<string, string>();
        foreach (var header in filterContext.HttpContext.Response.Headers.AllKeys)
            headers.Add(header, filterContext.HttpContext.Response.Headers[header]);

        Debugger.Break();
    }
} 

ヘッダーは区切りに表示されていないので、おそらくOutputCacheAttributeconfigureが何をするのでしょうかHttpContext.Current.Response.Cache

どのようfilterContext.HttpContext.Response.Cache.VaryByHeaders.UserCharSettrueであるか、たとえばfalsefilterContext.HttpContext.Response.Cache.VaryByHeaders.AcceptTypesであるかはわかりますが、ヘッダーには常に*と表示されます。Vary

可能な値は、のプロパティとしてリストされている4つの値だけfilterContext.HttpContext.Response.Cache.VaryByHeadersでしょうか?

乾杯。

4

2 に答える 2

7

解決策は使用ですResponse.Cache.SetOmitVaryStar(true)

    [OutputCache(Duration = 2,
         Location = OutputCacheLocation.Any,
         VaryByHeader = "Accept-Charset")]
    public ActionResult Index()
    {
        Response.Cache.SetOmitVaryStar(true);
        return View("ShowHeaders");
    }

私はまだこのスレッドでVary:*の何が問題になっているのかを理解しようとしています:HTTPヘッダーVary:*の意味は何ですか

于 2011-09-30T14:56:35.930 に答える
0

<%@ OutputCache duration = "2000" VaryByParam = "*" VaryByHeader = "Accept-Language"%>

于 2011-09-29T16:51:27.090 に答える