c# - VaryByCustom not working for session variable -


i'm using output cache web site login system. have global pages can accessed every user. these pages cached , use master page.

<%@ outputcache duration="3600" varybyparam="none" varybycustom="userid" %> 

i'm storing user login details in session. global.asax file here:

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; } 

i have panel in master page visible authenticated users. when user logins , views public page guest user sees authenticated user panel on page a. if guest first view page authenticated user not see panel on page a.

what part of code wrong? i'm using varybycustom first time.

edit

i've modified global.asax nothing written in text file:

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; } 

i think session["userid"] reason return null / or times return null, if user authenticated.

double check set before function ask it.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -