public static object Login(string userName, string password) { AjaxResult result = AjaxResult.Error("登陆失败"); try { AccessHelper acc = new AccessHelper(); DataTable dt = acc.GetDataTableFromDB("select Id,UserName,UserTitle from users where UserName='******' and Password='******'"); if (dt != null && dt.Rows.Count > 0) { SysContext.SetCurrent(dt.Rows[0][0].ToString()); SysContext.CurrentUserID = dt.Rows[0][0].ToString(); SysContext.CurrentUserName = dt.Rows[0][1].ToString(); SysContext.CurrentUserTitle = dt.Rows[0][2].ToString(); result = AjaxResult.Success("登陆成功"); } else { throw new Exception("登录失败,用户名或密码错误"); } } catch (Exception ex) { result = AjaxResult.Error(ex.Message); } return(result); }