前段登录: //登陆操作 function loginSys(username,password) { $.ajax({ type: "POST", dataType: "json", //cache:true, url: "Service/EasyUiService.ashx?Method=Login", data: { username: username, password: password }, success: function(json) { if (json.Flag[0].Status == 1) { window.location.href = "Index.aspx"; } else { $.messager.alert('错误', '账号或密码错误!', 'error'); } }, error: function() { $.messager.alert('错误', '获取账号信息失败...请联系管理员!', 'error'); } }); 后台模拟: HttpRequest Request; HttpResponse Response; HttpSessionState Session; HttpServerUtility Server; HttpCookie Cookie; public void ProcessRequest(HttpContext context) { //不让浏览器缓存 context.Response.Buffer = true; context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1); context.Response.AddHeader("pragma", "no-cache"); context.Response.AddHeader("cache-control", ""); context.Response.CacheControl = "no-cache"; context.Response.ContentType = "text/plain"; Request = context.Request; Response = context.Response; Session = context.Session; Server = context.Server; string method = Request["Method"].ToString(); MethodInfo methodInfo = this.GetType().GetMethod(method); methodInfo.Invoke(this, null); } /// <summary> /// 登陆 /// </summary> public void Login() { string username = Request["username"].ToString(); string password = Request["password"].ToString(); int flag = UserAccess.GetInstance().Login(username, password); int? roleId = RoleAccess.GetInstance().GetRoleIdByUsername(username); Cookie = new HttpCookie("RoleInfo"); Cookie["roleId"] = roleId.ToString(); Cookie.Expires = DateTime.Now.AddMonths(1); Response.Cookies.Add(Cookie); JsonConvert<object> jc = new JsonConvert<object>(); Response.Write(jc.ToStatus(flag)); } |
|