ProfileProviderAttribute(String) Konstruktor

Definicja

Tworzy nowe wystąpienie ProfileProviderAttribute klasy o określonej nazwie dostawcy profilu.

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)

Parametry

providerName
String

Nazwa dostawcy profilu dla właściwości .

Przykłady

Poniższy przykład kodu definiuje klasę dziedziczą po klasie w ProfileBase celu utworzenia profilu niestandardowego. Typ profilu niestandardowego jest określony w inherits atrybucie elementu konfiguracji profilu w pliku Web.config dla aplikacji. Aby zapoznać się z przykładem pliku konfiguracji, który określa implementację profilu niestandardowego, zobacz ProfileProviderAttribute omówienie klasy.

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

Uwagi

Klasa ProfileProviderAttribute służy do identyfikowania dostawcy profilu dla właściwości implementacji profilu niestandardowego. Implementacja profilu niestandardowego jest klasą dziedziczą po ProfileBase klasie abstrakcyjnej i definiuje właściwości profilu użytkownika, które nie są określone w elemecie konfiguracji profilu .

Dotyczy

Zobacz też