Adding roles dynamically to the asp.net role provider

234 Views Asked by At

I'm using the Asp.Net Role Provider that contains some roles. I would like to add some other roles that are coming from another database. Is there a way to do some kind of "union" between roles coming from the role provider and roles coming from my other database ?

To be more precise, I'm using forms authentication, I retrieve roles from my other database and store them in the FormsAuthenticationTicket. Then in AuthenticateRequest from Global.Asax, I generate the principal with the list of roles. But later when using User.IsInRole, it does not work for the list of roles I have assigned in AuthenticateRequest. What's the right direction to go ?

Christian

1

There are 1 best solutions below

0
On

You can create roles at runtime:

Dim strNewRole as String = "NEW"

If Not Roles.RoleExists(strNewRole) Then
    Roles.CreateRole(strNewRole)
End If

So you can still use your code to retrieve roles from another database and then use the code above for every role.