AJAX 实现用户登录验证

html页面中:





    
    
    



    用户名:
    密码:

UserLogin.ashx.cs页面中:
using XXX.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace XXX.WebApp
{
    /// 
    /// UserLogin 的摘要说明
    /// 
    public class UserLogin : IHttpHandler,System.Web.SessionState.IRequiresSessionState  //用Session要实现该接口
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string userName = context.Request["userName"];
            string userPwd=context.Request["userPwd"];
            BLL.UserInfoService UserInfoService = new BLL.UserInfoService();
            string msg = string.Empty;
            UserInfo userInfo = null;
            if (UserInfoService.ValidateUserInfo(userName, userPwd, out msg, out userInfo))
            {
                context.Session["userInfo"] = userInfo;
                context.Response.Write("ok:"+msg);
            }
            else
            {
                context.Response.Write("no:" + msg);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}


你可能感兴趣的:(ASP.NET,JQuery,Ajax)