各位大侠请教一下 谁用过 OutputCache 用了更新不了cookie
各位大侠请教一下 谁用过 OutputCache 用了更新不了cookie
页面设置
<%@ OutputCache Duration="100" VaryByParam="none" VaryByCustom="UserName"%>
重写
public override string GetVaryByCustomString(HttpContext context, string arg)
{
string key = string.Empty;
//arg = arg.ToLower(); //outputcache customer
//if (arg.Contains("UserName")) //Login User
//{
// key += "UserName:" + HttpContext.Current.User.Identity.Name + ";";
//}
// if (arg.Contains("admin")) // Is Admin User
//{ key += "admin:" + HttpContext.Current.User.Identity.Name + ";-"; }
//return key;
if (arg.Contains("UserName")) //Is UserName List
{
HttpCookie cookie = Request.Cookies["UserName"];
if (cookie != null)
return cookie.Value;
}
return base.GetVaryByCustomString(context,arg);
}