SettingsAllowAnonymousAttribute(Boolean) 构造函数

定义

创建 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 类,并定义 配置文件配置元素 中未指定的用户配置文件的属性。

适用于

另请参阅