ProfileProviderAttribute(String) 建構函式

定義

建立一個 ProfileProviderAttribute 類別的新執行個體,並命名為指定的設定檔提供者名稱。

C#
public ProfileProviderAttribute(string providerName);

參數

providerName
String

屬性設定檔提供者的名稱。

範例

下列程式代碼範例會定義繼承自 類別的 ProfileBase 類別,以建立自定義配置檔。 自訂設定檔的類型是在應用程式的 Web.config 檔案中設定檔組態項目的 屬性中指定inherits。 如需指定自定義配置檔實作的組態檔範例,請參閱 ProfileProviderAttribute 類別概觀。

C#
using System;
using System.Web.Profile;

namespace Samples.AspNet.Profile
{
  public class EmployeeProfile : ProfileBase
  {
    [SettingsAllowAnonymous(false)]
    [ProfileProvider("EmployeeInfoProvider")]
    public string Department
    {
      get { return base["EmployeeDepartment"].ToString(); }
      set { base["EmployeeDepartment"] = value; }
    }

    [SettingsAllowAnonymous(false)]
    [ProfileProvider("EmployeeInfoProvider")]
    public EmployeeInfo Details
    {
      get { return (EmployeeInfo)base["EmployeeInfo"]; }
      set { base["EmployeeInfo"] = value; }
    }
  }

  public class EmployeeInfo
  {
    public string Name;
    public string Address;
    public string Phone;
    public string EmergencyContactName;
    public string EmergencyContactAddress;
    public string EmergencyContactPhone;
  }
}

備註

類別 ProfileProviderAttribute 可用來識別自定義配置檔實作屬性的配置檔提供者。 自訂配置檔實作是繼承自抽象類的 ProfileBase 類別,並定義配置檔 組態專案中 未指定之使用者配置檔的屬性。

適用於

產品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

另請參閱