Click here to Skip to main content
15,884,739 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to have application level client side caching in asp.net

I have the following scenario. And doing the following currently:

Works fine in my local machine.

A master page and multiple content pages.

In master page I have a dropdown to select States in a country.
on the select of which I am assigning it to

C#
Cache["State"]=ddlStates.SelectedItem.value;


and in some pages I need to populate the repeaters depending on the state selected as follows:
C#
protected override void OnInit(object sender, EventArgs e)
{
   if(ViewState["StateFromGlobal"]==null)
   {
       ViewState["StateFromGlobal"]=Cache["State"];
   }
}
public void BindRepeater()
{
    myRepo=new BLLRepo();
    repeater1.datasource=myRepo.GetResultsByState(string.IsnullorWhiteSpace(Cache["State"].toString())?"":Cache["State"].toString())
repeater1.DataBind();
}


the above line of code says that fetch the Results matching the value in the Cache["State"]. If it is empty I'm using other sql Command that selects all the results regardless of the states.(However this is not concern rigth now).

But the Problem is!!
My doubt is if I deploy this on the web server and If any user in one city selects state "A" from dropdown having States "--Select State--", "A", "B", "C",...."Z" then, is that so the other user who visits the website sees "A" selected by default or the Default value "--Select State--"??

If this doesn'tAny other alternative's to ma
Posted
Updated 13-Aug-12 21:34pm
v3

I think website sees "A" selected by default. Because Cache value is shareble to all users. (I am not sure)

If you want to store state value from master page with access in every pages and not shareable to all users then you can go for session or cookie.
 
Share this answer
 
Comments
pradiprenushe 14-Aug-12 4:54am    
good answer
Pavan Navule 14-Aug-12 5:14am    
But Cookies are up to page level only right? But I want it to be get stored in the client machine so that in future if the user visits the website then it must be read from the cookie. But usage of session is temporary and the session ends when the user closes the browser.
You are storing cache from code behind which is stored at server side. This is not user specific or instance specific.(As you are storing it in normal way).
So you should use session for this thing rather than cache & you dont need to store it in viewstate as already storing it.
Main use of session is to store user specific data. Here you are also storing user specific data so use session for this.
 
Share this answer
 
Comments
Pavan Navule 14-Aug-12 5:14am    
Hi Pradip,
Please see my comment above.
pradiprenushe 14-Aug-12 5:21am    
Then you can not use session for this. You can use cookie.
Cookies are not on page level storage, viewstate is page level storage.
Pavan Navule 14-Aug-12 5:30am    
Cookies are not page level storage?? Then I presume it might be on application levle. Is it?

Even I tried using cookies but I got the error that cookie is null for every page.


I've thought of alternative solution.
I would like to put the States dropdown in a user control and use the output cache with location="Client" and then I may try to load the dropdown value in to the view state.
What say? I need to try it.
pradiprenushe 14-Aug-12 5:43am    
Look this is correcr syntax for cookie

Response.Cookies["test"].Value = "Valutostore" ;
Response.Cookies["test"].Expires = DateTime.Now.AddYears(1);

I will suggest you to use cookie. Try to find reason for what is happening. Cookie are application+machine specific. I think you get the point.
Pavan Navule 14-Aug-12 5:53am    
Ok I need to check why I'm getting exception. And also need to add additional functionality to change the cookie value on selectedItemChanged event of the dropdown. Thanks for the suggestions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900