public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true AuthenticateUserRequest loginModel = new AuthenticateUserRequest(); loginModel.Username = model.Username; loginModel.Password = model.Password; RestClient rc = new RestClient(); ApiResponseModel responseModel = await rc.Login(loginModel); ApiResultModel resultModel = responseModel.Result; //var result = await _signInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberMe, lockoutOnFailure: false); if (responseModel.Status && responseModel.Result != null) { await _signInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberMe, lockoutOnFailure : false); AuthenticateUserResultModel authUserResultModel = null; if (resultModel.GetType() == typeof(AuthenticateUserResultModel)) { authUserResultModel = (AuthenticateUserResultModel)resultModel; HttpContext.Session.SetString(SessionState.SessionKeyToken, authUserResultModel.Token); } _logger.LogInformation("User logged in."); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(View(model)); } } // If we got this far, something failed, redisplay form return(View(model)); }