Asp.net会话变量 [英] Asp.net session variable

查看:149
本文介绍了Asp.net会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#code后面的asp.net项目。我有一个名为GlobalVariable静态类在那里我存储一些信息,例如像当前选择的产品。

I have a asp.net project with c# code behind. I have a static class called GlobalVariable where I store some information, like the currently selected product for example.

不过,我看到的是,当有使用本网站的两个用户,如果一个改变选择的产品,如果它的变化给大家。静态变量似乎COMMUN给大家。

However, I saw that when there are two users using the website, if one changes the selected product, if changes it for everybody. The static variables seem to be commun to everybody.

我要创建(从C#code)某种会话变量只能从C#code使用,而不是只从页面,而是从任何类。

I would want to create (from the c# code) some kind of session variable used only from the c# code, but not only from the page, but from any class.

推荐答案

是静态变量是整个应用程序共享,他们是没有办法的私人用户/会话。

Yes static variables are shared by the whole application, they are in no way private to the user/session.

要从非页面类访问Session对象,你应该使用 HttpContext.Current.Session

To access the Session object from a non-page class, you should use HttpContext.Current.Session.

这篇关于Asp.net会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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