问题描述
我已经实现了一个小型Web应用程序。在我的应用程序中,我使用静态变量来全局存储数据。我正面临着静态变量的问题。我在两个不同的浏览器中打开我的应用程序。我有 这里的问题,静态变量为不同的浏览器全局存储值。我该如何解决这个问题。有没有更好的方法将静态变量转换为会话。
I have implemented one small web application. In my application i have used the static variables to store the data globally. I am facing the problem with the static variables. I am opening my application in two different browsers. I got the problem here the static variables are storing the value globally for different browsers. How can i solve this issue. Is there any better way to convert the static variables to the sessions.
推荐答案
//create a session variable and store the value you need to(Any datatype can be stored)
Session["sessionname"] = TheValueToBeStored;
//extract the value from the session to the variable of the corresponding type.
short Var_name= Convert.ToInt16(Session["sessionname"]);
谢谢....
Sijo
Thank you....
Sijo
Application["key"] = value;
这里有一个小链接,可以理解这背后的逻辑。
[]
如果我理解错误,请告诉我,我会尽力改进我的答案。
here is a small link to understand the logic behind doing this.
A Beginner''s Tutorial on ASP.NET State Management[^]
Let me know if I understood it incorrectly and I will try to refine my answer.
这篇关于哪个是将静态变量更改为会话的更好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!