In a public facing web app multi tenant app, I'm using ASP Identity 2.x
.
I let 3rd party's e.g. non-profits/comps self-register, create and populate their own roles and users. The code below is fine, if its an intranet scenarios where everyone belongs to the same company, it does not for work multiple non-profits
The non-profits registrants (understandably so) are naming roles with the same names, i.e. Managers
and Employees
etc. which are common/same across the database.
How can I extend ASP Identity to separate the roles per organization in a multi-tenant fashion, can you help me understand the design and how extend this, do I need a sub-role? i.e.
- what do I do to ensure roles are scoped per organization at the database, so that different org's can have the same role names?
and, what do I do at the middle tier, i.e. usermanager, role manager objects level (middle tier)
//Roles/Create [HttpPost] public ActionResult Create(FormCollection form) { try { context.Roles.Add(new Microsoft.AspNet.Identity.EntityFramework.IdentityRole() { \\ Question - can I add another level here like company?? Name = form["RoleName"] }); context.SaveChanges(); ViewBag.ResultMessage = "Role created successfully"; return RedirectToAction("RoleCreated"); } catch { return View(); } }`
Question- When adding a role, how do I separate the role to know which Role is from Which company when I add to the user?
public ActionResult RoleAddToUser(string UserName, string RoleName) { ApplicationUser user = context.Users.Where(u => u.UserName.Equals(UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault(); var account = new AccountController(); account.UserManager.AddToRole(user.Id, RoleName); ViewBag.ResultMessage = "Role created successfully !"; // prepopulat roles for the view dropdown var list = context.Roles.OrderBy(r => r.Name).ToList().Select(rr => new SelectListItem { Value = rr.Name.ToString(), Text = rr.Name }).ToList(); ViewBag.Roles = list; return View("ManageUserRoles"); }
how do I get the list of Roles and Users for that non-profit?
public ActionResult ManageUserRoles() { var list = context.Roles.OrderBy(r => r.Name).ToList().Select(rr => new SelectListItem { Value = rr.Name.ToString(), Text = rr.Name }).ToList(); ViewBag.Roles = list; return View(); }`