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

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;
            }
        }
    }
}

 

posted on 2012-08-31 10:53  风火网络科技  阅读(141)  评论(0)    收藏  举报

导航