System.Web.Security.Roles.Providers Property

Gets a collection of the role providers for the ASP.NET application.

Syntax

public static RoleProviderCollection Providers { get; }

Value

Documentation for this section has not yet been entered.

Remarks

The Roles.Providers property references all the role providers enabled for an application, including any providers added in the Web.config file. You can control which role providers are available for an application by using the providers element of the roleManager section in the Web.config file for your application.

The following example shows a roleManager section that removes any existing providers (such as those specified in the Machine.config file) and adds a System.Web.Security.SqlRoleProvider instance as the role provider for the application.

Example

<configuration>
  <connectionStrings>
    <add name="SqlServices" connectionString="Data Source=MySqlServer;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />
  </connectionStrings>

  <system.web>
    <roleManager defaultProvider="SqlProvider" 
      enabled="true"
      cacheRolesInCookie="true"
      cookieName=".ASPROLES"
      cookieTimeout="30"
      cookiePath="/"
      cookieRequireSSL="false"
      cookieSlidingExpiration="true"
      cookieProtection="Encrypted">

      <providers>
        <clear/>
        <add
          name="SqlProvider"
          type="System.Web.Security.SqlRoleProvider"
          connectionStringName="SqlServices"
          applicationName="MyApplication" />
         </providers>

    </roleManager>
  </system.web>
</configuration>

You can obtain a strongly typed reference to a provider from the Roles.Providers collection by indexing the role provider by name and casting it as the desired type.

You can obtain a reference to the default provider for an application using the Roles.Provider property.

Requirements

Namespace: System.Web.Security
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0