Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I afraid standard roles-related stuff of ASP.NET is not what you need. You can try to change authentication module so it will:</p> <ol> <li>Log you in with cookie.</li> <li>Determine what roles does your visitor have. Perhaps you will use some special table that corresponds user and site.</li> <li>Make custom principal with user roles enumerated and assign Identity and Principal to the current request.</li> </ol> <p>I also don't think that making special roles for each site is good idea. When you would have hundred sites, you would also have two hundred roles. Pretty unmanageable, I afraid. </p> <p>When we were solving similar task, we were just not using standard controls. We had single set of roles used on all sites. Membership of concrete user is determined according to current site and his relations to this site. </p> <p>Addition: Another possibility to investigate is Application that exists in ASP.NET authentication system. Maybe it's possible to isolate each subsite into separate application?</p> <p><strong>Update:</strong> Method that works for our application.</p> <ol> <li><p>Do not make a lot of cloned roles. Use only two: users and admin. If your sites are public then "users" role could be just global - user on one site doesn't differ from user on another site. If "users" and "everyone" are different roles, then of course "users" should also be bound to a site.</p></li> <li><p>Use standard ASP.NET Membership users, but do not use standard role mechanism. </p></li> <li><p>Make a mechanism for storing relation between site and user. It could be simple table that holds site id, user is and role.</p></li> <li><p>What you have to override is IsInRole method. (Method<strong>s</strong> to be exact, i'll cover it later). This method is in IPrinciple interface, so you have to make your own principal object. It's quite simple. </p> <ol> <li>Method IsInRole of this type should look take current site (from HttpRequest) look into the site-user table and get roles</li> </ol></li> <li><p>Then you have to associate your principal with a request. Do it in PostAuthenticateRequest event.</p></li> <li><p>There is also RoleProvider. Honestly I'm not sure when is it used, but it also have IsInRole method. We can override it in the same way. But other methods of this provider are harder. For example AddUsersToRoles. It accepts array of user names and roles, but to what context (site) should it be added? To current? Not sure, because I don't know when this method is called. So it requires some experiments. I see (Reflector helps) that RopePrincipal by itself uses RoleProvider to fetch list of roles, so maybe it's implement only RoleProvider, using standard principal. For our application this is not a case, so I can't say what problems could be hidden here.</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload