我正在使用输出缓存作为登录系统的网站。我有全球网页,每个用户都可以访问。这些页面被缓存并且也使用母版页。VaryByCustom不适用于会话变量
<%@ 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然后验证的用户不会看到在页面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;
}
好的,我发现我无法访问当前会话变量“会话状态在此上下文中不可用”。试图现在解决它。 – 2010-11-16 09:56:16