SettingsAllowAnonymousAttribute(Boolean) 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建类的新实例 SettingsAllowAnonymousAttribute ,并指定是否允许匿名访问关联的配置文件属性。
public:
SettingsAllowAnonymousAttribute(bool allow);
public SettingsAllowAnonymousAttribute(bool allow);
new System.Web.Profile.SettingsAllowAnonymousAttribute : bool -> System.Web.Profile.SettingsAllowAnonymousAttribute
Public Sub New (allow As Boolean)
参数
- allow
- Boolean
true 如果匿名用户可以访问关联的配置文件属性,则为否则 false。
示例
以下示例定义从类继承以创建自定义配置文件的 ProfileBase 类。 自定义配置文件的类型是在 inherits 应用程序的 Web.config 文件中 配置文件 配置元素的属性中指定的。 有关指定自定义配置文件实现的配置文件示例,请参阅 SettingsAllowAnonymousAttribute 类概述。
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
注解
该 SettingsAllowAnonymousAttribute 类用于确定如果用户是匿名用户,是否可以访问自定义配置文件实现的属性。 有关启用匿名标识的信息,请参阅 anonymousIdentification 配置元素。
SettingsAllowAnonymousAttribute如果未指定配置文件属性,则不允许匿名访问配置文件属性。
自定义配置文件实现是从抽象类继承的 ProfileBase 类,定义配置文件的属性,这些属性未在 配置文件 配置元素中指定。