.NET WEBAPP中的Session
来源:互联网 发布:沃尔沃xc60轮毂数据 编辑:程序博客网 时间:2024/05/21 10:26
初学,写个小程序,数据库用ACCESS,后台是C#,ACTION全部用ASHX文件,前台用EXTJS,采用SESSION方法判断用户是否登录
用户登录时在SESSION中写入数据
context.Session["UserName"] = context.Request.Form["loginname"];
//数据库表中每条记录都有ROLEID,取数据时判断如select * from table where roleid=roleid
context.Session["RoleId"] = currole.ID;
//在主要的页面上作用户是否登录判断
context.Session["isLogin"] = true;
用户注销时将这些记录清空
由于老是要取且判断SESSION内容,于是写了个类来处理Session的内容,注意第一个方法最好用
/// <summary>
/// 此类只包括静态函数,专门读取SESSION的内容
/// </summary>
public class SessionItems:IRequiresSessionState
{
public static object GetSessionObj(string SessionName)
{
if (HttpContext.Current.Session[SessionName] != null)
{
return HttpContext.Current.Session[SessionName];
}
return null;
}
public static string getSessionUserName()
{
if (HttpContext.Current.Session["UserName"] != null)
{
return (Convert.ToString(HttpContext.Current.Session["UserName"]));
}
return null;
}
public static int getSessionRoleID()
{
if (HttpContext.Current.Session["RoleId"] != null)
{
return (Convert.ToInt32(HttpContext.Current.Session["RoleId"]));
}
return 0;
}
public static bool getSessionIsLogin()
{
if (HttpContext.Current.Session["isLogin"] != null)
{
return (Convert.ToBoolean(HttpContext.Current.Session["isLogin"]));
}
return false;
}
}
在ASHX中直接调用SessionItem类的静态方法
注意不管在哪个类中调用,那个类必须实现接口IRequiresSessionState,同时添加using System.Web.SessionState;
- .NET WEBAPP中的Session
- asp.net中的session
- asp.net中的session
- 关于ASP.NET中的Session
- asp.net中的session使用
- asp.net中的session使用
- ASP.NET中的Session对象
- ASP.NET中的Session解析
- ASP.NET 中的Session统一管理
- 详解ASP.net中的session
- ASP.NET 中的Session介绍
- 关于ASP.NET中的session
- 开发框架WebApp.net
- webapp中的单位
- asp.net 中的截取 Session 变量(翻译)
- Asp.net 中的Session问答,研究.
- .net中的session丢失(1)
- ASP.NET中的session存储模式
- 如何在Oracle中使用Java存储过程 (详解)
- 关于内存问题和使用内存建议
- USB 基本知识
- 复制 tphkload.exe 时出错
- 【REST 】REST 介绍
- .NET WEBAPP中的Session
- 清空并删除SQL Server数据库中的日志
- MySQL配置文件my.cnf中文详解
- vbScript中WScript.Shell对象的run和exec使用心得
- Vortex2D.NE的Scene派生类的构造过程
- Vortex2D.NET使用ScreenManager的Draw时花屏的原因
- Reflector 7 破解激活及使用(图解)
- Vortex2D.NET一个开源的2D图形引擎-介绍
- When C# Anonymous Method is Asynchronously Invoked