当大小限制生效时

当大小限制生效时

本文介绍了当大小限制生效时,cookie的最佳替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用一个相当大的数据库。我想在pageload事件期间填充页面的webcontrols(下拉列表),以使网页具有最大的灵活性。例如,我有一个下拉列表,用户可以选择该列表,该列表将从数据表的特定列的唯一行填充。

I have been working with a fairly huge database. I want to populate the webcontrols(dropdownlists) of the page during pageload event to give the webpage as much flexibility as possible. For example, I have a dropdownlist ,that user can select, which will be populated from the unique rows of a specific column of a datatable.

现在,我不希望在每次页面加载发生时都触发oracle查询,因​​为这会大大降低网页速度(每次大约1分钟)。所以我开始考虑将cookie作为解决方案。我很快发现,cookie大小(4kb)的限制对我而言太小了。如果我真的想在本地存储数据行,则需要大约10-15kb的大小!因此,我尝试搜索是否有任何方法可以增加cookie大小限制以满足我的需求,而我发现可能的解决方案是localstorage。

Now, i don't want to fire the oracle query each time page load happens because that will slow down the webpage significantly (about 1mins each time). So i started to think of cookies as solution. I soon found out that limitation of cookie size (4kb) is way too small for my purpose. I will need around 10-15kb of size if i really want to store the datarows locally! So I tried to search if there were any way to increase the cookie size limitation to accommodate my needs and I found the possible solution is localstorage.


  1. 是否真的有增加cookie大小限制的方法?

  2. 最简单的选择是什么?真的是本地存储吗?还是还有其他需要研究的?

详细信息:我正在使用C#/ ASP.NET + ORACLE

details: I am using C#/ASP.NET + ORACLE

推荐答案

这是ASP.Net中状态信息的所有存储选项-

Here are all storage options for state information in ASP.Net -


  • 缓存-存储在服务器上并在用户之间共享的内存池

  • 会话-存储在服务器上,并且对于每个用户都是唯一的

  • Cookies -存储在客户端上,并与每个HTTP请求一起传递给服务器

  • QueryString -作为一部分传递完整的URL字符串

  • Context.Items -HttpContext,仅持续该请求的生存期

  • 个人资料-存储在数据库中,并在多个会话中维护信息

  • Cache - a memory pool stored on the server and shared across users
  • Session - stored on the server and unique for each user
  • Cookies - stored on the client and passed with each HTTP request to the server
  • QueryString - passed as part of the complete URL string
  • Context.Items - HttpContext and lasts only the lifetime of that request
  • Profile - stored in a database and maintains information across multiple sessions

您的方案有两种选择-


  • 如果跨用户共享数据,请使用缓存

  • 如果每个用户的数据都是唯一的,请使用 Session

  • If data shared across users, use Cache
  • If data is unique for each users, use Session

理想情况下,您不希望存储在 ViewState 中,除非您这样做会导致页面很沉重,除非您配置为将ViewState存储在Sql Server中(超出此问题的范围)。

Ideally, you do not want to store in ViewState it will make your page very heavy unless you configure to store ViewState in Sql Server (which is out of the scope of this question).

localStorage -并非所有浏览器都可以处理localStorage,因此请确保先进行检查。

localStorage - Not all browsers can handle localStorage, so make sure you check it first.

<script type="text/javascript">
   if(window.localStorage)  {
      window.localStorage.SetItem('keyName','valueToUse');
      // OR
      window.localStorage.keyName = 'valueToUse';
   }
</script>

仅供参考: ASP.NET不会提供处理本地存储的特定方法;您只能通过javascript在客户端进行操作。

FYI: ASP.NET does not offer specific methods for handling local storage; you can only manipulate at client side via javascript.

这篇关于当大小限制生效时,cookie的最佳替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 22:23