问题
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:
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.
来源:https://stackoverflow.com/questions/3584078/how-to-override-silvelright-4-ria-service-authenticationservice-user-isinrole