0

Sorry if double, but the answer is to find and failed.

It looks like my code create a group on the forum:

public async Task<ActionResult> Create(ForumGroups fg)
    {
        if (ModelState.IsValid)
        {
            ApplicationUser user = ad.Users.Where(m => m.UserName == HttpContext.User.Identity.Name).FirstOrDefault();

            db.Organizations.Add(fg);
            db.SaveChanges();

            await RoleManager.CreateAsync(new ApplicationRole { Name = string.Format("GroupAdministrator{0}", organization.Id) });
            await UserManager.AddToRoleAsync(user.Id, string.Format("GroupAdministrator{0}", organization.Id));


            return RedirectToAction("Index");
        }

        return View(fg);
    }

The role is created fine but the problem is that the access to the newly created forum does not appear immediately. Taking inventory is standard here such code:

 @if (Request.IsAuthenticated && User.IsInRole(string.Format("GroupAdministrator{0}", Model.Id)))
{
    <h4>Administrator</h4>
        <p>
            @Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
            @Html.ActionLink("Back to List", "Index")
        </p>
} 

How to make so when you create a group, the user will instantly have access to it ?

Macro
  • 33
  • 1
  • 7
  • Look through this: https://stackoverflow.com/q/29285406/809357 and this: https://stackoverflow.com/q/24286489/809357 – trailmax Jul 25 '17 at 21:23
  • Basically roles are stored in the cookie and cookie needs refreshed when you assign new roles to a user. – trailmax Jul 25 '17 at 21:24

0 Answers0