語言

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 承該類別以建立自訂設定檔。 自訂設定檔的類型會在應用程式 Web.config 檔案中設定檔設定元素的屬性中指定inherits。 關於指定自訂設定檔實作的設定檔範例,請參見 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 類別用於判斷當使用者為匿名使用者時,是否能存取自訂設定檔實作的屬性。 關於啟用匿名識別的資訊,請參閱 匿名識別 設定元素。

若設定檔屬性未指定 NO SettingsAllowAnonymousAttribute ,則不允許匿名存取該設定檔屬性。

自訂設定檔實作是一個繼承自 ProfileBase 抽象類別的類別,並定義使用者設定檔的屬性,這些屬性未在 設定檔 設定元素中指定。

適用於

另請參閱