存储值的位置,以便可以在整个页面中访问它。 [英] Where to store value so that it can be accessed throughout the page.

查看:61
本文介绍了存储值的位置,以便可以在整个页面中访问它。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个大页面中,我使用differnet-2方法访问存储在cookie中的schoolId至少50次。这意味着要获取相同的schoolid值,它将50次从函数中获取相同的schoolid。是否有任何优化选项可以从cookie中获取值一次并在整个页面中使用它。该项目适用于多用户。所以据我所知,我不应该使用静态变量来存储值。我应该使用session,viewstate还是cache?对于我来说,获取值一次并在页面上的任何位置使用的最佳选项是什么?

In one of my large page i am accessing schoolId stored in cookie at least 50 times in differnet-2 methods. That means to fetch the same schoolid value it is going to the function 50 times to fetch same schoolid from cookie. Is there any optimized option to get the value from the cookie one time and use that throughout the page. The project is for multiuser. So as far as i know i should not use static vaiable to store the value. Should i use session, viewstate or cache? What is the best option for me to fetch the value once and use everywhere on the page

推荐答案

对于一个页面,请使用ViewState。如果你想访问所有页面,那么使用Session。
For one page, use ViewState. If you want to access through out all pages, then use Session.


我建​​议将它存储在页面级别(私有类级别变量)中,并在整个页面中使用它。



对于存储用户特定数据(如schoolId),存储会话是一个好主意,因为它会在用户注销后自动过期。
I would suggest to store it in page level (private class level variable) and use it throughout the page.

For storing user specific data (like your schoolId), storing in session is a good idea as it will expire automatically once user logs out.


这篇关于存储值的位置,以便可以在整个页面中访问它。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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