SettingsAllowAnonymousAttribute(Boolean) Konstruktor

Definition

Skapar en ny instans av SettingsAllowAnonymousAttribute klassen och anger om anonym åtkomst till den associerade profilegenskapen ska tillåtas.

public:
 SettingsAllowAnonymousAttribute(bool allow);
public SettingsAllowAnonymousAttribute(bool allow);
new System.Web.Profile.SettingsAllowAnonymousAttribute : bool -> System.Web.Profile.SettingsAllowAnonymousAttribute
Public Sub New (allow As Boolean)

Parametrar

allow
Boolean

true om anonyma användare kan komma åt den associerade profilegenskapen; annars false.

Exempel

I följande exempel definieras en klass som ärver från ProfileBase klassen för att skapa en anpassad profil. Typen av anpassad profil anges i inherits attributet för profilkonfigurationselementet i Web.config-filen för ett program. Ett exempel på en konfigurationsfil som anger en anpassad profilimplementering finns i klassöversikten 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

Kommentarer

Klassen SettingsAllowAnonymousAttribute används för att identifiera om en egenskap för en anpassad profilimplementering kan nås om användaren är en anonym användare. Information om hur du aktiverar anonym identifiering finns i konfigurationselementet anonymousIdentification .

Om inget SettingsAllowAnonymousAttribute anges för en profilegenskap tillåts inte anonym åtkomst till profilegenskapen.

En anpassad profilimplementering är en klass som ärver från den ProfileBase abstrakta klassen och definierar egenskaper för användarprofilen som inte anges i profilkonfigurationselementet.

Gäller för

Se även