ProfileProviderAttribute Kelas

Definisi

Mengidentifikasi penyedia profil untuk properti profil pengguna.

public ref class ProfileProviderAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class ProfileProviderAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Property)>]
type ProfileProviderAttribute = class
    inherit Attribute
Public NotInheritable Class ProfileProviderAttribute
Inherits Attribute
Warisan
ProfileProviderAttribute
Atribut

Contoh

Contoh kode berikut menentukan kelas yang mewarisi dari ProfileBase kelas untuk membuat profil kustom. Jenis profil kustom ditentukan dalam inherits atribut elemen konfigurasi profil dalam file Web.config untuk aplikasi.

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

Keterangan

Kelas ProfileProviderAttribute ini digunakan untuk mengidentifikasi penyedia profil untuk properti implementasi profil kustom. Implementasi profil kustom adalah kelas yang mewarisi dari ProfileBase kelas abstrak dan menentukan properti untuk profil pengguna yang tidak ditentukan dalam elemen konfigurasi profil . Anda dapat menentukan jenis kustom untuk profil pengguna menggunakan inherits atribut elemen konfigurasi profil dalam file Web.config untuk aplikasi, seperti yang ditunjukkan dalam contoh berikut.

<configuration>  
  <connectionStrings>  
    <add name="SqlServices" connectionString=  
      "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />  
  </connectionStrings>  

  <system.web>  
    <authentication mode="Forms" >  
      <forms loginUrl="login.aspx"  
        name=".ASPXFORMSAUTH" />  
    </authentication>  

    <authorization>  
      <deny users="?" />  
    </authorization>  

    <profile inherits="Samples.AspNet.Profile.EmployeeProfile"  
      defaultProvider="SqlProvider">  
      <providers>  
        <clear />  
        <add  
          name="SqlProvider"  
          type="System.Web.Profile.SqlProfileProvider"   
          connectionStringName="SqlServices"   
          description="SQL Profile Provider for Sample"/>   
        <add  
          name="EmployeeInfoProvider"  
          type="System.Web.Profile.SqlProfileProvider"   
          connectionStringName="SqlServices"   
          description="SQL Profile Provider for Employee Info"/>   
      </providers>  

      <properties>  
        <add name="GarmentSize" />  
      </properties>  
    </profile>  
  </system.web>  
</configuration>  

Konstruktor

ProfileProviderAttribute(String)

Membuat instans ProfileProviderAttribute baru kelas dengan nama penyedia profil yang ditentukan.

Properti

ProviderName

Mendapatkan nama penyedia profil untuk properti profil pengguna.

TypeId

Ketika diimplementasikan di kelas turunan, mendapatkan pengidentifikasi unik untuk ini Attribute.

(Diperoleh dari Attribute)

Metode

Equals(Object)

Mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
GetHashCode()

Mengembalikan kode hash untuk instans ini.

(Diperoleh dari Attribute)
GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
IsDefaultAttribute()

Ketika ditimpa di kelas turunan, menunjukkan apakah nilai instans ini adalah nilai default untuk kelas turunan.

(Diperoleh dari Attribute)
Match(Object)

Saat ditimpa di kelas turunan, mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Implementasi Antarmuka Eksplisit

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Memetakan sekumpulan nama ke sekumpulan pengidentifikasi pengiriman yang sesuai.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Mengambil informasi jenis untuk objek, yang dapat digunakan untuk mendapatkan informasi jenis untuk antarmuka.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Mengambil jumlah antarmuka informasi jenis yang disediakan objek (baik 0 atau 1).

(Diperoleh dari Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Menyediakan akses ke properti dan metode yang diekspos oleh objek.

(Diperoleh dari Attribute)

Berlaku untuk

Lihat juga