如何在类文件中声明会话 [英] How to declare session in class file

查看:88
本文介绍了如何在类文件中声明会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sqldatreader读取sqlcommand和
时需要的类文件中编写登录代码.

I am writing login code in a class file where i need if sqldatreader read the sqlcommand and

if (paswd == dr["password"].ToString()) then i want to store
userId in session like this:
if (paswd == dr["password"].ToString())
{
    Session["userid"]=dr["userid"].ToString();
}


但在课堂上文件会话不起作用.

请任何人帮我怎么做.
在此先感谢


but in class file session is not working.

please any one help me how can i do this.
Thanks in advance

推荐答案

Session属性提供对HttpSessionState类的属性和方法的编程访问.因为ASP.NET页包含对System.Web命名空间的默认引用(包含HttpContext类),所以您可以在.aspx页上引用HttpContext的成员,而无需对HttpContext进行完全限定的类引用.例如,您可以仅使用Session("SessionVariable1")来获取或设置会话状态变量SessionVariable1的值.但是,类文件不会继承System.web命名空间.所以我们需要如下访问,
The Session property provides programmatic access to the properties and methods of the HttpSessionState class. Because, ASP.NET pages contain a default reference to the System.Web namespace (which contains the HttpContext class), you can reference the members of HttpContext on an .aspx page without the fully qualified class reference to HttpContext. For example, you can use just Session("SessionVariable1") to get or set the value of the session state variable SessionVariable1. However, class file will not inherit System.web namespace. So we need access like below,
HttpContext.Current.Session["userid"] = dr["userid"].ToString();


这篇关于如何在类文件中声明会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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