Невозможно изменить форму после правильной авторизации пользователя в форме входа в систему
Hi. I'm using DirectoryServices.AccountManagement for authorizing users to log into my web application. The code I used is like the following for authorizing and it can correctly authorize active directory users. As I read a variety of articles, I need to write something like [Authorize(Users="DOMAIN\UserName")] on top my controller classes in order to specify that which controller, the user has access. But now my problem is what should I write in the body of "if (ctx.ValidateCredentials(userName, password)" after the user' authorization is successful. I wrote something like "return this.RedirectToLocal(returnUrl);" but after clicking the login button, although in the console it prints "You are logged in" but still the login form remains. I appreciate if anyone can suggest me a solution accordingly.
[HttpPost] [ValidateAntiForgeryToken] public async Task<IActionResult> Signin(SigninViewModel model, string returnUrl = null) { this.ViewData["ReturnUrl"] = returnUrl; using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "tehran.iri")) { // validate the user's credentials //var result = ctx.ValidateCredentials(model.UserName, model.Password); // try { if (ctx.ValidateCredentials(model.UserName, model.Password)) { // credentials are OK --> allow user in Debug.Writeline("You are logged in"); return this.RedirectToLocal(returnUrl); } else { this.TempData["ErrorMessage"] = "The username and/or password are incorrect!"; return this.View(model); // credentials aren't OK --> send back error message } } }
Что я уже пробовал:
HttpPost] [ValidateAntiForgeryToken] public async Task<IActionResult> Signin(SigninViewModel model, string returnUrl = null) { this.ViewData["ReturnUrl"] = returnUrl; using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "tehran.iri")) { // validate the user's credentials //var result = ctx.ValidateCredentials(model.UserName, model.Password); // try { if (ctx.ValidateCredentials(model.UserName, model.Password)) { // credentials are OK --> allow user in Debug.Writeline("You are logged in"); return this.RedirectToLocal(returnUrl); } else { this.TempData["ErrorMessage"] = "The username and/or password are incorrect!"; return this.View(model); // credentials aren't OK --> send back error message } } }