次のようにGetVaryByCustomString
メソッドをオーバーライドします。
public override string GetVaryByCustomString(HttpContext context, string custom)
{
if (custom.Equals("User", StringComparison.InvariantCultureIgnoreCase))
{
// Return the user name/login as a value that will invalidate cache per authenticated user.
return context.User.Identity.Name;
}
return base.GetVaryByCustomString(context, custom);
}
このanwserに以下のコメント、セッション変数を使用して、ユーザーがログインしているかどうかを確認していると言います。そのような認証を管理するのがベストプラクティスではないことを教えてください。
ソリューションは、セッションの値に応じてキャッシュを無効にする方法は、これをやっている:
再び
VaryByCustom
<%@ OutputCache VaryByCustom="Session" .... %>
は、あなたがそれをstring
は本当に良いですな意味を与えることによって、好きなstring
値であることと、将来の開発者をさせることができますあなたがしていたことを知ることができます。
次にあなたがする必要があるすべてである
public override string GetVaryByCustomString(HttpContext context, string custom)
{
if (custom.Equals("Session", StringComparison.InvariantCultureIgnoreCase))
{
// make sure that the session value is convertible to string
return (string)context.Session["Here you put your session Id"];
}
return base.GetVaryByCustomString(context, custom);
}
をオーバーライドします。それが役に立てば幸い。
ASP.Net WebFormsまたはASP.Net MVCを使用しているテクノはどれですか? – CodeNotFound
@CodeNotFound webforms –