自己的一段AJAX和Session操作的Code

<%@ WebHandler Language="C#" class="userLogin" %>

using System;
using System.Web;
using System.Data;
using System.Web.SessionState;

public class userLogin : IHttpHandler, IRequiresSessionState{
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        if (context.Session["account"] != null)
        {
            huayi.cme_model.v_user_info sessionUser = (huayi.cme_model.v_user_info)context.Session["account"];
            context.Response.Write(sessionUser.name);
            return;
        }
        string loginName = context.Request["name"].ToString();
        string logPwd = context.Request["pwd"].ToString();
        huayi.cme_dal.SystemAccount sacc = new huayi.cme_dal.SystemAccount();
        DataTable resultDt=sacc.checkLoginUser(WebUtility.InputText(loginName,40),WebUtility.InputText(logPwd,40),1);
        if (resultDt == null)
        {
            context.Response.Write("error");
            return;
        }
        string resultStr = resultDt.Rows[0][0].ToString();
        if (resultStr == "0")
            context.Response.Write("nameerror");
        else if (resultStr == "1")
            context.Response.Write("pwderror");
        else
        {
            context.Response.Write(resultStr);
            string uid=resultDt.Rows[0][1].ToString();
            huayi.cme_model.v_user_info uinfo = new huayi.cme_model.v_user_info();
            uinfo = sacc.getUserInfoById(uid.ToUpper());
            string name=uinfo.name.ToString();
            string img = uinfo.img_url;
            context.Session["account"] = uinfo;
            //SessionHelper.Account = uinfo;
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

你可能感兴趣的:(session)