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 类继承的类,以创建自定义配置文件。 自定义配置文件的类型在 inherits 应用程序的 Web.config 文件中 配置文件 配置元素的 属性中指定。 有关指定自定义配置文件实现的配置文件的示例,请参阅 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 并定义 配置文件配置元素 中未指定的用户配置文件的属性。

适用于

另请参阅