您的位置:首页 > 编程语言 > ASP

asp.net中在一般处理程序中使用session

2012-08-31 10:53 746 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BLL;
using Model;
using System.Web.SessionState;
using System.Text;

namespace Exam
{
/// <summary>
/// Login 的摘要说明
/// </summary>
public class Login : IHttpHandler,IRequiresSessionState
{

public void ProcessRequest(HttpContext context)
{
string param = context.Request.Form["param"];
if (param.Equals("login"))
{
string name = context.Request.Form["name"];
string pwd = context.Request.Form["pwd"];
UserInfo model = UserBLL.Login(name, pwd);
if (model != null)
{
context.Session.Add("user", model);
context.Response.Write("1");
}
else
{
context.Response.Write("0");
}
context.Response.End();
}
else if (param.Equals("exit"))
{
context.Session.RemoveAll();
}
else if (param.Equals("userRole")) {
int userId=int.Parse(context.Request.Form["user"]);
int roleId=int.Parse(context.Request.Form["role"]);
UserBLL.UpdateUserRole(userId,roleId);
}
else if (param.Equals("rightUpdate"))
{
int roleId =int.Parse(context.Request.Form["roleId"]);
string str = context.Request.Form["strList"];
str=str.Substring(0, str.Length - 1);
RightBLL.UpdateRoleRight(roleId, str);
}
else if (param.Equals("getRight")) {
int roleId = int.Parse(context.Request.Form["roleId"]);
List<RightInfo> list=RightBLL.GetRightIdByRoleId(roleId);
StringBuilder sb = new StringBuilder();
foreach (RightInfo item in list)
{
sb.Append(item.Id+",");
}
string rights=sb.ToString().Substring(0,sb.Length-1);
context.Response.Write(rights);
}
}

public bool IsReusable
{
get
{
return false;
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: