views:

162

answers:

1

I've started out with the Silverlight 4 Navigation Application template (RIA Services enabled). (As I really don't like the bloated Business Application Template) I've added an Authentication Service and I'm able to authenticate users, but want to override the User.IsInRole method.

WebContext.Current.User.IsInRole("Guest");

But I cannot find any place to override the behaviour.

+1  A: 

What are you trying to do? User.IsInRole is an implementation of IPrincipal.IsInRole and really shouldn't be overridden.

If you want to set the user roles, you can do it on the server in your AuthenticationService by overridding the GetAuthenticatedUser or GetAnonymousUser methods.

If you want a method similar to IsInRole, you can extend the User type with a partial class on the client and add whatever methods make sense.

Kyle McClellan
Well, I have an empty Authentication Service, and in my app I want to be able to call WebContext.User.IsInRole("somerole") and that will cause a lookup in our database to see if that user is effectively in that role. We have a table 'User' and a table 'Role' and then a link table 'UserInRole' to create an M<->M relation.
TimothyP
You won't be able to do the lookup when someone calls IsInRole (Silverlight forces async communication). You can do the lookup earlier, though, in GetAuthenticatedUser. Alternately, you should be able to use a standard RIA Services association to pass the Roles for the user to the client. That could be useful, but in most cases just distilling that table to a list of strings on the server will be the best approach.
Kyle McClellan