Export (0) Print
Expand All

ProfileManager.Providers Property

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

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

public static ProfileProviderCollection Providers { get; }

Property Value

Type: System.Web.Profile.ProfileProviderCollection
A ProfileProviderCollection of the profile providers configured for the ASP.NET application.

ExceptionCondition
HttpException

An attempt was made to get the Providers property value without at least Medium permission.

The Providers property references all of the profile providers enabled for an application, including providers added in the machine configuration and providers added in all Web.config files. You can control which profile providers are available for an application using the providers element of the profile section in the configuration file. For example, the following Web.config file removes the profile providers specified in parent configuration files and adds a SqlProfileProvider instance as the profile provider for the application.

<configuration>
  <connectionStrings>
    <add name="SqlServices" connectionString=
      "Data Source=MySqlServer;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />
  </connectionStrings>
  <system.web>
    <profile enabled="true" defaultProvider="SqlProvider">
      <providers>
        <clear />
        <add name="SqlProvider"
          type="System.Web.Profile.SqlProfileProvider"
          connectionStringName="SqlServices"
          applicationName="MyApplication" />
      </providers>
    </profile>
  </system.web>
</configuration>

When specifying the profile section, you must specify a default provider by setting the defaultProvider attribute. If you do not specify a profile section in your Web.config file, the values from the machine configuration are used and the SqlProfileProvider instance named AspNetSqlProvider is established as the default provider.

You can obtain a strongly typed reference to a provider from the Providers collection by indexing the profile 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.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Profile" %>
<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>List Enabled Providers</title>
</head>
<body>

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

</body>
</html>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft