D
Dave
Hi,
I'm using Windows authentication with impersonation turned on but I wanted
to pull user roles from my database. Once I person logs in, I want to check
their roles.
I have the following code that loads an array of roles for a
person(hardcoded in this sample but will be pulled from a database later base
on the user's identity.)
However, in subsequent pages when I want to show certain links for an
"Admin", User.IsInRole("Admin") always returns false. Is my implementation
wrong? I don't want to rely on Windows groups but would rather maintain the
roles in my db which I have more control.
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (Request.IsAuthenticated)
{
//These will eventually be pulled from database's UserRole table...
string[] arrRoles = new string[]{"Admin", "User"};
//Add our Principal to the current context
System.Threading.Thread.CurrentPrincipal = new
System.Security.Principal.GenericPrincipal(Context.User.Identity, arrRoles);
}
}
I'm using Windows authentication with impersonation turned on but I wanted
to pull user roles from my database. Once I person logs in, I want to check
their roles.
I have the following code that loads an array of roles for a
person(hardcoded in this sample but will be pulled from a database later base
on the user's identity.)
However, in subsequent pages when I want to show certain links for an
"Admin", User.IsInRole("Admin") always returns false. Is my implementation
wrong? I don't want to rely on Windows groups but would rather maintain the
roles in my db which I have more control.
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (Request.IsAuthenticated)
{
//These will eventually be pulled from database's UserRole table...
string[] arrRoles = new string[]{"Admin", "User"};
//Add our Principal to the current context
System.Threading.Thread.CurrentPrincipal = new
System.Security.Principal.GenericPrincipal(Context.User.Identity, arrRoles);
}
}