Some extra info:
When I programatically 'use' the roleprovider everything works fine, e.g.:
Dim provider As RoleProvider = New CustomRoleProvider
Dim roles() As String = provider.GetRolesForUser("Tom")
Dim roleexists As Boolean = provider.IsUserInRole("Tom", "user")
This all returns the correct results.
But when I use:
System.Web.Security.Roles.IsUserInRole("Tom", "user")
I get incorrect results.
I guess some binding or something needs to be done after authentication.
I've found an article on putting some extra code in a global asax file
but that doesn't seem to work either. This is the code I've tried:
Protected Sub Application_AuthenticateRequest(ByVal sender As Object,
ByVal e As System.EventArgs)
Try
If Request.IsAuthenticated Then
Dim roleprovider As RoleProvider = New CustomRoleProvider
Dim roles As String() =
roleprovider.GetRolesForUser(User.Identity.Name)
HttpContext.Current.User = New
System.Security.Principal.GenericPrincipal(User.Id entity, roles)
End If
Catch ex As Exception
Console.Write(ex.ToString)
End Try
End Sub
Peter Bromberg [C# MVP] schreef:
Then I'd suggest running this in debug mode with the source code project for
your role provider in the solution. Set breakpoints at the appropriate places
and trace through your code to find out what may be wrong.
If your breakpoints don't get hit, that means your configuration setup is
wrong.
Peter