Output Caching

Susana

Newcomer
Joined
Jul 7, 2003
Messages
11
hello to all,

can anyone help me? I want to cache my pages based on VeryByParam=userid. The value for userid comes from a Session.

The problem is almost all the pages in the application should be cached by userid and i don't want to recode all of them just to pass parameters like
Response.Redirect("../Menu.aspx?userid=" & Session("userid")).

Is there anyway that i could add immediately the value to the directive? example,

<%@ OutputCache Duration="2700" VaryByParam="Session('userid')" %>

but i already tried this one and it won't work.

or how do i use the value coming from a hidden field. I also tried this one:
<%@ OutputCache Duration="2700" VaryByParam="userid" %>
...
...
..
..
<FORM>....
<input id=userid type=hidden value=<%=Session("userid")%>
</FORM>

but even if a different user already log, same page as the first user would be displayed.

Sorry if my explanation is not clear enough but i hope atleast you understand what I meant...

hope to hear from you... anyone :confused:
thanks.
 
You need to override the HttpApplication.GetVaryByCustomString() method.

C#:
public override string GetVaryByCustomString(HttpContext context, string custom)
{
    if (custom == "userid")
    {
        return HttpContext.Current.Session.Item["userid"].ToString();
    }
}

Place this in the global.asax file (inside script tags of course).
 
Hi Robby, sorry if i replied quite late already... thanks for your time... what i want is i want to cache the menu page for each userid... the menu items displayed on the menu page vary depending on the user's access..

Robby said:
I'm not sure if I understand, do you want to cache menu items for each userID?
 
hello Derek Stone,

sorry for making you wait... and thank you for your reply... your suggestion is correct, based on other articles I read. But I can't make it work on my application... I might be missing something...

here is what I am doing:

in HTML of the aspx file I placed:
<%@ OutputCache Duration="2700" VaryByParam="none" VaryByCustom="uid" %>

and in global.asax.vb I placed these:
Public Overrides Function GetVaryByCustomString(ByVal context As HttpContext, ByVal arg As String) As String
If (arg = "uid") Then
Return HttpContext.Current.Session.Item("userid").ToString()
End If
End Function


but whenever I logged in twice with different users, same menu page is displayed. The cached page of the first user. help me further please...

thank you so much...
 
Back
Top