Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • *Gurus*
Posted

You need to override the HttpApplication.GetVaryByCustomString() method.

 

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).

  • 2 weeks later...
Posted

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..

 

I'm not sure if I understand' date=' do you want to cache menu items for each userID?[/quote']
Posted

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...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...