D
Dave
Hi, i created my own Users, Roles, & UserRoles table in my SQL DB. I'm
using the following code to associate the user's roles from what's in my
tables.
Snippet 1
----------
//In a page base class, Load the user's roles for subsequent IsInRole
security checks...where userRoles is an array of roleIds pulled from the
UserRole table.
Context.User = new
System.Security.Principal.GenericPrincipal(Context.User.Identity, userRoles);
Snippet 2
----------
I then check the user's role later in the page.
if (Context.User.IsInRole("Admin")
{
//enable some controls here...
}
However, it seems I always have run the Snippet #1 since the user's role
context is not persistent between requests.
I then see that the SqlRoleProvider is designed to do this and apparently
you can cache the roles specifying the roleManager cookie in the web.config.
My question is whether SqlRoleProvider has essentially replaced the method
I'm using? My method is more basic in terms of what I've added to the
database but if I can't persist the user's context in anyway, is it too
inefficient? If I need to track additional user columns I'm guessing I just
tweak the tables/procs created by regaspnet_regsql
using the following code to associate the user's roles from what's in my
tables.
Snippet 1
----------
//In a page base class, Load the user's roles for subsequent IsInRole
security checks...where userRoles is an array of roleIds pulled from the
UserRole table.
Context.User = new
System.Security.Principal.GenericPrincipal(Context.User.Identity, userRoles);
Snippet 2
----------
I then check the user's role later in the page.
if (Context.User.IsInRole("Admin")
{
//enable some controls here...
}
However, it seems I always have run the Snippet #1 since the user's role
context is not persistent between requests.
I then see that the SqlRoleProvider is designed to do this and apparently
you can cache the roles specifying the roleManager cookie in the web.config.
My question is whether SqlRoleProvider has essentially replaced the method
I'm using? My method is more basic in terms of what I've added to the
database but if I can't persist the user's context in anyway, is it too
inefficient? If I need to track additional user columns I'm guessing I just
tweak the tables/procs created by regaspnet_regsql