很抱歉,如果加倍,但答案是找到并失败。
看起来我的代码在论坛上创建了一个小组:
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);
}
角色创建正常,但问题是对新创建的论坛的访问不会立即显示。 以库存为标准是这样的代码:
@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>
}
如何在创建群组时这样做,用户可以立即访问它?