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 類別,以建立自定義配置檔。 自訂設定檔的類型是在應用程式 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 可用來識別如果使用者是匿名使用者,是否可以存取自定義配置檔實作的屬性。 如需啟用匿名識別的相關信息,請參閱 anonymousIdentification 組態專案。
SettingsAllowAnonymousAttribute如果未指定配置檔屬性,則不允許匿名存取配置檔屬性。
自訂配置檔實作是繼承自抽象類的 ProfileBase 類別,並定義配置檔 組態專案中 未指定之使用者配置檔的屬性。