How to: Enable Roles in Open Ria Services
[ This document was written for WCF Services Version 1 Service Pack 2 and might not be up to date Please see Release Notes or Changelog for a list of changes since WCF RIA Services ]
This topic demonstrates how to enable roles in your Open Ria Services solution if you have previously enabled authentication. You can retrieve a user’s roles only after the user has been authenticated. To configure your solution for authentication, see How to: Enable Authentication in Open Ria Services. You restrict access to a domain operation to members of a role by applying the RequiresRoleAttribute attribute to the method for the domain operation.
Roles are used to specify which group of authenticated users can access certain resources. Roles in Open Ria Services build upon roles in ASP.NET. For more information about roles, see Understanding Role Management.
To configure the server project
In the server project, open the Web.config file.
In the \ section, enable the manager role by adding the \ element.
The following example shows how to enable the manager role.
In the membership database, create the required roles and assign users to the roles as needed.
For more information, see Understanding Role Management. For an example of creating roles, see Walkthrough: Using Authentication Service with Silverlight Business Application or Walkthrough: Using Authentication Service with Silverlight Navigation Application.
To restrict access to a domain operation to only members of a specified role, apply the RequiresRoleAttribute attribute to the domain operation.
The following example specifies that only members of the Managers role can access the domain operation.
To access roles in the client project
To check whether the user belongs to the required role, access the Roles property or call the IsInRole method on the WebContext.Current.User object.
The following example checks whether the user belongs to a role named Managers before calling the domain operation.
If you want to make the WebContext object available in XAML, add the current WebContext instance to the application resources in the Application.Startup event before creating the root visual.
The following example shows how to add the WebContext instance as an application resource.
See Also
Tasks
Walkthrough: Using Authentication Service with Silverlight Navigation Application
Walkthrough: Using Authentication Service with Silverlight Business Application
Last updated