ProfileManager.Providers 属性

定义

获取 ASP.NET 应用程序的配置文件提供程序的集合。

public:
 static property System::Web::Profile::ProfileProviderCollection ^ Providers { System::Web::Profile::ProfileProviderCollection ^ get(); };
public static System.Web.Profile.ProfileProviderCollection Providers { get; }
member this.Providers : System.Web.Profile.ProfileProviderCollection
Public Shared ReadOnly Property Providers As ProfileProviderCollection

属性值

ProfileProviderCollection

为 ASP.NET 应用程序配置的配置文件提供程序的 ProfileProviderCollection

例外

在不具有起码的 Providers 权限的情况下尝试获取 Medium 属性值。

示例

下面的代码示例列出了为应用程序及其各自的类型启用的提供程序。

<%@ 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>
<%@ Page Language="VB" %>
<%@ 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>

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

</body>
</html>

注解

Providers 属性引用为应用程序启用的所有配置文件提供程序,包括计算机配置中添加的提供程序以及所有Web.config文件中添加的提供程序。 可以使用配置文件中配置文件节的 提供程序 元素来控制应用程序可用的 配置文件 提供程序。 例如,以下Web.config文件删除父配置文件文件中指定的配置文件提供程序,并将实例 SqlProfileProvider 添加为应用程序的配置文件提供程序。

<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>

指定 配置文件 节时,必须通过设置 defaultProvider 属性来指定默认提供程序。 如果未在Web.config文件中指定节 profile ,将使用计算机配置中的值,并将 SqlProfileProvider 名为 AspNetSqlProvider 的实例建立为默认提供程序。

可以通过按名称为配置文件提供程序编制索引并将其强制转换为所需类型,从 Providers 集合中获取对提供程序的强类型引用。

适用于

另请参阅