語言

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; }
static member Providers : System.Web.Profile.ProfileProviderCollection
Public Shared ReadOnly Property Providers As ProfileProviderCollection

屬性值

其中一 ProfileProviderCollection 組設定檔提供者為 ASP.NET 應用程式所設定。

例外狀況

有人試圖在至少未經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 ,並將其鑄造成所需類型,從而從集合中取得強型別的提供者參考。

適用於

另請參閱