Currently when I create a new user and the default Register() logs in the user My _layout displays what links depending on @if (User.IsInRole("User")).
Right now when I create the user the
@if (Request.IsAuthenticated) displays the correct links.
Next it checks the Role and depending on the role it displays what it needs.
Currently no matter the role the user gets whatever the else {} displays.
If I log the user out and then log the user back in Then all the CORRECT layout links are shown. Any idea how I can fix this or why this is?
Here is my register its pretty much the default one…
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser
{
UserName = model.UserName,
Email = model.Email,
Name = model.Name,
PhoneNumber = model.PhoneNumber,
Birthday = Convert.ToDateTime(model.Birthday),
DateCreated = DateTime.Now,
};
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
await this.UserManager.AddToRoleAsync(user.Id, model.UserRoles);
TempData["Success"] = "User Created Successfully";
return RedirectToAction("Index", "Home");
}