public IHttpActionResult LogIn(string userName, string password, int type) { var c = HttpContext.Current.Items["accountID"] as string; SimpleResult result = new SimpleResult(); var item = doctorInforService.GetDoctorInfor(userName, password, type); if (userName != "123" && password != "123") { result.Status = Result.FAILURE; result.Msg = "用户名或密码错误"; return(Json(result)); } FormsAuthenticationTicket token = new FormsAuthenticationTicket(0, userName, DateTime.Now, DateTime.Now.AddHours(1), true, string.Format("{0}&{1}", item.accountID, password), FormsAuthentication.FormsCookiePath); //返回登录结果、用户信息、用户验证票据信息 var Token = FormsAuthentication.Encrypt(token); //将身份信息保存在session中,验证当前请求是否是有效请求 CacheMgr.Insert(Token, item, CacheType.Token); result.Resource = Token; return(Json(result)); }