In Winform I need ASP.NET like membership and roles stuff. But Roles doesn't work

Posted by user512602 on Stack Overflow See other posts from Stack Overflow or by user512602
Published on 2011-01-15T21:51:40Z Indexed on 2011/01/15 21:53 UTC
Read the original article Hit count: 250

Filed under:
|
|

Hi, following http://www.theproblemsolver.nl/usingthemembershipproviderinwinforms.htm I set up the membership & roles providers in app.config and try use it in code.

Authentication works well, bur roles always returns empty roles array for connected user.

This part works:

If Membership.ValidateUser(userName, password) Then

        ' Set the current application principal information to a known user
        Dim identity As GenericIdentity
        Dim principal As RolePrincipal
        Dim user As MembershipUser

        user = Membership.GetUser(userName)
        identity = New GenericIdentity(user.UserName)
        principal = New RolePrincipal(identity)
        Threading.Thread.CurrentPrincipal = principal

This one doesn't:

If principal.IsInRole("Club") Then
            LoggedInUserRole = "Club"
            Return True
            Exit Function
        End If

No error is thrown though.

Similarly, if I try to add a user to a known, existing role, an exception is thrown :

 If Not Roles.IsUserInRole(userName, "club") Then
            Roles.AddUserToRole(userName, "club")
        End If

Exception msg is: Cannot find role '' (I mean the role name isn't given back in exception.)

Any clue?

Please do not tell me to use Windows Client Administration within project services, I need my own SQL DB connection + the client app services is a bloated dfeature, bug prone.

© Stack Overflow or respective owner

Related posts about winforms

Related posts about membership