简体   繁体   中英

Issue with ASP.NET 2.2 user role

I have a problem with user role.

In my application, when a user registers, a confirmation e-mail is sent, which then refers to an internal page of the application that allows the registration process to be completed.

The method of the controller that is called recognizes through these functions the calling user:

ApplicationUser CurrentUser = await GetCurrentUserAsync();

public Task<ApplicationUser> GetCurrentUserAsync() => _userManager.GetUserAsync(_httpContextAccessor.HttpContext.User);

The user has the role "Utente" but is not recognized by the system. In order for it to be recognized, I have to log in again.

My problem is that the user registration form inserts it into the "Users" group and sends the confirmation email to the user. The user clicks on the link on this e-mail ends the registration and then should be able to use the application without having to log in again.

I think I can solve the problem with a solution similar to the following:

add SignInManager.SignIn(user, false, false); (if you dont have user, var user = UserManager.FindById(User.Identity.GetUserId())) before RedirectToAction("Index", "Members");

Can someone kindly tell me how to do it in ASP.NET CORE 2.2?

Thanks.

I solved the problem refreshing the login after assigning user to the role as follows:

await _userManager.AddToRoleAsync(user, "Utente");

await _signInManager.SignInAsync(user, isPersistent: false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM