如果我们不在课堂上工作,我们可以使用会话变量吗??? [英] can we use session variable if we are not working in classes???

查看:75
本文介绍了如果我们不在课堂上工作,我们可以使用会话变量吗???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想问的是,如果我们不在类中工作,是否可以使用会话变量....

我的意思是,当我们创建应用程序时,我们定义了自己的类,然后在整个应用程序中使用会话变量.但是,如果我们不在课堂上工作怎么办?难道我们用它来保存用户名,然后在应用程序中进一步使用吗?

em hell tensed:(

Hi ,

I want to ask can we use the session variable if we are not working in classes....

I mean when we create an application we define our own classes then we use session variable throughout application. But what if we are not working in classes? Cant we use it to save user name and then for further use in application?

em hell tensed:(

推荐答案

,只要您有对System.Web的引用,并且您的类在Web服务器的上下文中运行,则可以执行此操作:

as long as you have a reference to System.Web and your class is running in the context of a web server, you can do this:

var mySessionItem = HttpContext.Current.Session["SessionKey"];


我们可以通过配置文件使用会话状态-请参见 http://msdn.microsoft.com/en-us/library/ms972429.aspx [ ^ ].
We can use session states via the config file - see http://msdn.microsoft.com/en-us/library/ms972429.aspx[^].


我不确定您的意思是"我想问我们可以使用如果我们不在课堂上工作,则使用会话变量...."

从技术上讲,每件事都是对象.即使您不创建类或看起来对您来说也不是一类,但幕后仍然存在一类.例如,您可以在aspx代码中引用session对象

I am not exactly sure what you mean by "I want to ask can we use the session variable if we are not working in classes...."

Technically speaking, every thing is an object. Even if you don''t create or seems to be a class to you, there is a class behind the scene. Take for instance, you can reference to session object in your aspx code

<![CDATA[<%=Session["Bla Bla"]%>]]>



在这种情况下,您不在类代码中,但是它是您的Page 类的一部分.

因此,简短的答案是,您可以在* class *之外引用session对象的实例.从真正的意义上讲,该代码将成为您的Page类的一部分.



in this case, you are not in a class code, but it is part of your Page class.

So, the short answer, there are instances you can reference to session object outside your *class*. In true sense, the code will be part of your Page class.


这篇关于如果我们不在课堂上工作,我们可以使用会话变量吗???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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