ProfileProviderAttribute(String) 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
使用指定的配置文件提供程序名称创建类的新实例 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 类,定义配置文件的属性,这些属性未在 配置文件 配置元素中指定。