views:

109

answers:

2

Is it possible to specify what is returned by RoleProvider.GetRoles() if a user is not logged in? I was thinking in case of a 'Guest' user account.

A: 

RolePrincipal.GetRoles needs to know who the user is in order to return the Roles it belongs to.

Oded
So then is there any way to add a 'Guest' role of some sort if there is nothing for it to lookup?
Stacey
+1  A: 

You could implement a custom role provider and override the GetRolesForUser method to return a guest role if no username is passed.

Sheff
I've tried that. If no username is provided the method doesn't even fire.
Stacey
The problem is that I was calling System.Web.Security.Roles.GetRolesForUser - instead of System.Web.Security.Roles.Provider.GetRolesForUser. Thank you.
Stacey