三层架构 Session 该怎么写
主页上有个登陆 但是不知道怎么保存!有些页面要登陆后才能访问! using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// CUserInfo 的摘要说明
/// </summary>
public class CUserInfo
{
/// <summary>
/// 用户ID,对应是在数据库里的Y_ID字段的值
/// </summary>
public static int UserID
{
get { return GetUserID() ; }
set { System.Web.HttpContext.Current.Session["UserID"]= value;}
}
/// <summary>
/// 用户名称,对应在数据库里的Y_Name字段的值
/// </summary>
public static string UserName
{
get { return (string)System.Web.HttpContext.Current.Session["UserName"]; }
set { System.Web.HttpContext.Current.Session["UserName"] = value; }
}
/// <summary>
/// 用户编号:对应在数据库里的Y_PassWord,也就是登陆的密码
/// </summary>
public static string UserPassWord
{
get { return (string)System.Web.HttpContext.Current.Session["UserPassWord"]; }
set { System.Web.HttpContext.Current.Session["UserPassWord"] = value; }
}
/// <summary>
/// 用户权限:对应在数据库里的Y_QuanXian
/// </summary>
public static string UserQuanXian
{
get { return (string)System.Web.HttpContext.Current.Session["UserQuanXian"]; }
set { System.Web.HttpContext.Current.Session["UserQuanXian"] = value; }
}
/// <summary>
/// 用户性别:对应在数据库里的Y_XingBie
/// </summary>
public static string UserSex
{
get { return (string)System.Web.HttpContext.Current.Session["UserSex"]; }
set { System.Web.HttpContext.Current.Session["UserSex"] = value; }
}
public CUserInfo()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private static int GetUserID()
{
if (System.Web.HttpContext.Current.Session["UserID"] == null)
return 0;
else
return (int)System.Web.HttpContext.Current.Session["UserID"];
}
/// <summary>
/// 清空登陆的所有信息
/// </summary>
public static void ClearUserInfo()
{
UserID = 0;
UserName = "";
UserPassWord = "";
UserQuanXian = "";
UserSex = "";
}
/// <summary>
/// 检测当前是否登陆成功了
/// </summary>
/// <returns>true,表示已经成功登陆了,false,表示没有登陆</returns>
public static bool CheckLogin()
{
if (UserID == 0)
return false;
else
return true;
}
}
这个类不能写在 DAL 里面