ProfileProviderAttribute 类

定义

为用户配置文件属性标识配置文件提供程序。

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
继承
ProfileProviderAttribute
属性

示例

下面的代码示例定义一个从 ProfileBase 类继承的类,以创建自定义配置文件。 自定义配置文件的类型在 inherits 应用程序的 Web.config 文件中 配置文件 配置元素的 属性中指定。

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 并定义 配置文件配置元素 中未指定的用户配置文件的属性。 可以使用应用程序的 Web.config 文件中配置文件配置元素的 属性为用户配置文件inherits指定自定义类型,如以下示例所示。

<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>  

构造函数

ProfileProviderAttribute(String)

用指定的配置文件提供程序名称创建 ProfileProviderAttribute 类的新实例。

属性

ProviderName

获取用户配置文件属性的配置文件提供程序的名称。

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。

(继承自 Attribute)
GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

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

将一组名称映射为对应的一组调度标识符。

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于

另请参阅