Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Membership Class
 Providers Property
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Membership..::.Providers Property

Updated: November 2007

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

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

Visual Basic (Declaration)
Public Shared ReadOnly Property Providers As MembershipProviderCollection
Visual Basic (Usage)
Dim value As MembershipProviderCollection

value = Membership.Providers
C#
public static MembershipProviderCollection Providers { get; }
Visual C++
public:
static property MembershipProviderCollection^ Providers {
    MembershipProviderCollection^ get ();
}
J#
/** @property */
public static MembershipProviderCollection get_Providers()
JScript
public static function get Providers () : MembershipProviderCollection

Property Value

Type: System.Web.Security..::.MembershipProviderCollection

A MembershipProviderCollection of the membership providers configured for the ASP.NET application.

The Providers property references all of the membership providers enabled for an application, including providers added in the Web.config file for the application and the Machine.config file for all applications. You can control which membership providers are available for an application using the providers element of the membership section in the configuration for your application. For example, the following sample shows the membership section in the Web.config file for an application that removes the SqlMembershipProvider instance (AspNetSqlProvider) specified in the machine configuration file and adds a SqlMembershipProvider instance named SqlProvider as the default membership provider for the application.

<configuration>
  <connectionStrings>
    <add name="SqlServices" connectionString="Data Source=MySqlServer;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />
  </connectionStrings>
  <system.web>
    <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="20">
      <providers>
        <remove name="AspNetSqlProvider" />
          <add name="SqlProvider"
            type="System.Web.Security.SqlMembershipProvider"
            connectionStringName="SqlServices"
            enablePasswordRetrieval="false"
            enablePasswordReset="true"
            requiresQuestionAndAnswer="true"
            passwordFormat="Hashed"
            applicationName="/" />
      </providers>
    </membership>
  </system.web>
</configuration>

When specifying the membership section, you must specify the defaultProvider attribute. If you do not specify a membership section in your Web.config, the values from the machine configuration are used and the SqlMembershipProvider instance named AspNetSqlProvider is established as the defaultProvider.

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

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

Visual Basic
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Configuration.Provider" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
<head>
<title>List Enabled Providers</title>
</head>
<body>

<%
For Each p As ProviderBase In Membership.Providers
  Response.Write(p.Name & ", " & p.GetType().ToString() & "<br />")
Next
%>

</body>
</html>

C#
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Configuration.Provider" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
<head>
<title>List Enabled Providers</title>
</head>
<body>

<%
foreach (ProviderBase p in Membership.Providers)
  Response.Write(p.Name + ", " + p.GetType() + "<br />");
%>

</body>
</html>

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

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker