public bool ValidateUser(string bankname, string username, string password) { bankDBAccess bankDBProvider = new bankDBAccess(); UserPrincipal _userprincipal = bankDBProvider.getLoginInfoByBankName(bankname, username); if (_userprincipal == null) { _errInfo = "当前用户名不存在!"; return(false); } string pwd = _userprincipal.Password; if (password == pwd) { setFormsAuthenticationTicket(_userprincipal.SubbranchID + "|" + username, true); HttpContext.Current.User = _userprincipal; return(true); } else { _errInfo = "密码错误!"; return(false); } }
void context_AuthenticateRequest(object sender, EventArgs e) { HttpApplication application = (HttpApplication)sender; HttpContext context = application.Context; HttpCookie authCookie = context.Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie == null) { //如没有提取到身份验证信息 return; } string loginName = getGuidFromCookie(authCookie); if (loginName == "") { //如没有提取到身份验证信息 return; } UserPrincipal curUser = getUserFromCacheByLoginName(loginName); if (curUser == null) { bankDBAccess bankDBprovider = new bankDBAccess(); curUser = bankDBprovider.getSubbranchLoginInfo(loginName); if (curUser != null) { saveDataToCache(curUser.SubbranchID, curUser); } } if (curUser == null) { return; } HttpContext.Current.User = curUser; //HttpContext.Current.User = new UserPrincipal(); }