我正在使用带有登录系统的网站的输出缓存。我有每个用户都可以访问的全局页面。这些页面被缓存,并且还使用母版页。
<%@ OutputCache Duration="3600" VaryByParam="none" VaryByCustom="userid" %>
我正在会话中存储用户登录详细信息。我的global.asax文件位于此处:
public override string GetVaryByCustomString(HttpContext context, string arg)
{
string result = String.Empty;
if (arg == "userid")
{
object o = Session["UserID"];
if (o != null) { result = o.ToString(); }
}
else { result = base.GetVaryByCustomString(context, arg); }
return result;
}
我在母版页中有一个面板,对经过身份验证的用户可见。当用户登录并查看公共页面时,另一位来宾用户也会在页面a上看到“已验证用户”面板。如果来宾首先查看页面a,则已验证用户不会在页面a上看到该面板。
我的代码哪一部分是错误的?我正在使用
VaryByCustom
第一次。
编辑
我这样修改了我的global.asax,但文本文件中没有任何内容:
public override string GetVaryByCustomString(HttpContext context, string arg)
{
string result = String.Empty;
FileInfo t = new FileInfo(Server.MapPath("App_Data\\debug.txt"));
StreamWriter Tex = t.AppendText();
Tex.WriteLine("GetVaryByCustomString: " + arg);
if (arg == "userid")
{
object o = Session["UserID"];
if (o != null) { result = o.ToString(); }
Tex.WriteLine("Checked UserID: " + o + Tex.NewLine);
}
else { result = base.GetVaryByCustomString(context, arg); }
Tex.Close();
return result;
}