How to: Use the ASP.NET Role Provider with a Service
Article
The ASP.NET role provider (in conjunction with the ASP.NET membership provider) is a feature that enables ASP.NET developers to create Web sites that allow users to create an account with a site and to be assigned roles for authorization purposes. With this feature, any user can establish an account with the site, and log in for exclusive access to the site and its services. This is in contrast to Windows security, which requires users to have accounts in a Windows domain. Instead, any user who supplies their credentials (the user name/password combination) can use the site and its services.
The role provider feature uses a SQL Server database to store user information. Windows Communication Foundation (WCF) developers can take advantage of these features for security purposes. When integrated into a WCF application, users must supply a user name/password combination to the WCF client application. To enable WCF to use the database, you must create an instance of the ServiceAuthorizationBehavior class, set its PrincipalPermissionMode property to UseAspNetRoles, and add the instance to the collection of behaviors to the ServiceHost that is hosting the service.
Configure the role provider
In the Web.config file, under the <system.web> element, add a <roleManager> element and set its enabled attribute to true.
Set the defaultProvider attribute to SqlRoleProvider.
As a child to the <roleManager> element, add a <providers> element.
As a child to the <providers> element, add an <add> element with the following attributes set to appropriate values: name, type, connectionStringName, and applicationName, as shown in the following example.
XML
<!-- Configure the Sql Role Provider. --><roleManagerenabled ="true"defaultProvider ="SqlRoleProvider" ><providers><addname ="SqlRoleProvider"type="System.Web.Security.SqlRoleProvider"connectionStringName="SqlConn"applicationName="MembershipAndRoleProviderSample"/></providers></roleManager>
Learn how the ASP.NET membership provider supports websites that let users create a user name and password for access without having a Windows domain account.