ProfileProviderAttribute(String) 建構函式

定義

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

public:
 ProfileProviderAttribute(System::String ^ providerName);
public ProfileProviderAttribute (string providerName);
new System.Web.Profile.ProfileProviderAttribute : string -> System.Web.Profile.ProfileProviderAttribute
Public Sub New (providerName As String)

參數

providerName
String

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

範例

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

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;
  }
}
Imports System.Web.Profile

Namespace Samples.AspNet.Profile

  Public Class EmployeeProfile
    Inherits ProfileBase

    <SettingsAllowAnonymous(False)> _
    <ProfileProvider("EmployeeInfoProvider")> _
    Public Property Department As String
      Get
        Return MyBase.Item("EmployeeDepartment").ToString()
      End Get
      Set
        MyBase.Item("EmployeeDepartment") = value
      End Set
    End Property

    <SettingsAllowAnonymous(False)> _
    <ProfileProvider("EmployeeInfoProvider")> _
    Public Property Details As EmployeeInfo
      Get
        Return CType(MyBase.Item("EmployeeInfo"), EmployeeInfo)
      End Get
      Set
        MyBase.Item("EmployeeInfo") = value
      End Set
    End Property
  End Class

  Public Class EmployeeInfo
    Public Name As String
    Public Address As String
    Public Phone As String
    Public EmergencyContactName As String
    Public EmergencyContactAddress As String
    Public EmergencyContactPhone As String
  End Class

End Namespace

備註

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

適用於

另請參閱