Roles.Providers Property

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

Namespace: System.Web.Security
Assembly: System.Web (in system.web.dll)

public static RoleProviderCollection Providers { get; }
/** @property */
public static RoleProviderCollection get_Providers ()

public static function get Providers () : RoleProviderCollection

Not applicable.

Property Value

A RoleProviderCollection that contains the role providers configured for the ASP.NET application.

Exception typeCondition


Role management is not enabled.

The 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 SqlRoleProvider instance as the role provider for the application.

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

    <roleManager defaultProvider="SqlProvider" 

          applicationName="MyApplication" />


You can obtain a strongly typed reference to a provider from the 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 Provider property.

The following code example lists the providers enabled for an application and their respective types.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Configuration.Provider" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" >
<title>List Enabled Providers</title>

foreach (RoleProvider p in Roles.Providers)
  Response.Write(p.Name + ", " + p.GetType() + "<br />");


Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions