asp.net中的应用程序级客户端缓存 [英] Application level Client side caching in asp.net

查看:53
本文介绍了asp.net中的应用程序级客户端缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想在asp.net中具有应用程序级别的客户端缓存

我有以下情况.目前正在执行以下操作:

在我的本地计算机上工作正常.

一个母版页和多个内容页.

在母版页中,我有一个下拉菜单选择一个国家/地区的国家.
在将其分配给
的选择上

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

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



在某些页面中,我需要根据选择的状态填充中继器,如下所示:



and in some pages I need to populate the repeaters depending on the state selected as follows:

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



上面的代码行说获取与Cache ["State"]中的值匹配的结果.如果为空,我将使用其他sql命令选择所有结果,而不管状态如何.(但是现在不考虑严格性).

但是问题是!!
我的疑问是我是否将其部署在Web服务器上,以及是否一个城市中的任何用户从具有状态"--Select State-","A","B","C"等的下拉列表中选择状态"A". .."Z"是这样,以便其他访问该网站的用户看到默认情况下选择的"A"或默认值"--Select State--" ??

如果这没有替代ma



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

推荐答案

,我认为网站默认会选择"A".因为缓存值对所有用户都是共享的. (我不确定)

如果要存储主页中的状态值,但每个页面中都不能访问,并且不能与所有用户共享,则可以进行会话或cookie.
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.


您要存储来自代码的缓存,其后是存储在服务器端.这不是特定于用户或特定于实例的.(就像您以常规方式存储它一样.)
因此,您应该为此使用会话而不是缓存,并且不需要将其存储在已存储的viewstate中.
会话的主要用途是存储用户特定的数据.在这里,您还存储了用户特定的数据,因此请为此使用会话.
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.


这篇关于asp.net中的应用程序级客户端缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆