WebPartsSection.Personalization 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 WebPartsPersonalization 物件,可讓您指定 Web 組件個人化提供者,並設定 Web 組件個人化授權。
public:
property System::Web::Configuration::WebPartsPersonalization ^ Personalization { System::Web::Configuration::WebPartsPersonalization ^ get(); };
[System.Configuration.ConfigurationProperty("personalization")]
public System.Web.Configuration.WebPartsPersonalization Personalization { get; }
[<System.Configuration.ConfigurationProperty("personalization")>]
member this.Personalization : System.Web.Configuration.WebPartsPersonalization
Public ReadOnly Property Personalization As WebPartsPersonalization
屬性值
WebPartsPersonalization 物件,可讓您指定個人化提供者,並設定個人化授權。
- 屬性
範例
下列程式碼範例示範如何使用 Personalization 屬性。
// Get the current DefaultProvider property value.
Console.WriteLine(
"Current DefaultProvider value: '{0}'",
webPartsSection.Personalization.DefaultProvider);
// Set the DefaultProvider property.
webPartsSection.Personalization.DefaultProvider =
"ASPNetSQLPersonalizationProvider";
// Add a provider.
webPartsSection.Personalization.Providers.Add(
new ProviderSettings("CustomProvider",
"MyCustomProviders.Provider"));
// List current providers.
for (int pi = 0;
pi < webPartsSection.Personalization.Providers.Count; pi++)
{
Console.WriteLine(" #{0} Name={1} Type={2}", pi,
webPartsSection.Personalization.Providers[pi].Name,
webPartsSection.Personalization.Providers[pi].Type);
}
// Add an authorization.
AuthorizationRule ar =
new AuthorizationRule(AuthorizationRuleAction.Allow);
ar.Verbs.Add("ModifyState");
ar.Users.Add("Admin");
webPartsSection.Personalization.Authorization.Rules.Add(ar);
// List current authorizations.
for (int ai = 0;
ai < webPartsSection.Personalization.Authorization.Rules.Count;
ai++)
{
Console.WriteLine(" #{0}:", ai);
AuthorizationRule aRule =
webPartsSection.Personalization.Authorization.Rules[ai];
Console.WriteLine(" Verbs=");
foreach (string verb in aRule.Verbs)
Console.WriteLine(" * {0}", verb);
Console.WriteLine(" Roles=");
foreach (string role in aRule.Roles)
Console.WriteLine(" * {0}", role);
Console.WriteLine(" Users=");
foreach (string user in aRule.Users)
Console.WriteLine(" * {0}", user);
}
' Get the current DefaultProvider property value.
Console.WriteLine( _
"Current DefaultProvider value: '{0}'", _
webPartsSection.Personalization.DefaultProvider)
' Set the DefaultProvider property.
webPartsSection.Personalization.DefaultProvider = _
"ASPNetSQLPersonalizationProvider"
' Add a provider.
webPartsSection.Personalization.Providers.Add( _
New ProviderSettings("CustomProvider", _
"MyCustomProviders.Provider"))
' List current providers.
Dim pi As Integer
For pi = 0 To webPartsSection.Personalization.Providers.Count - 1
Console.WriteLine(" #{0} Name={1} Type={2}", pi, _
webPartsSection.Personalization.Providers(pi).Name, _
webPartsSection.Personalization.Providers(pi).Type)
Next
' Add an authorization.
Dim ar As AuthorizationRule = _
New AuthorizationRule(AuthorizationRuleAction.Allow)
ar.Verbs.Add("ModifyState")
ar.Users.Add("Admin")
webPartsSection.Personalization.Authorization.Rules.Add(ar)
' List current authorizations.
Dim ai As Integer
For ai = 0 To _
webPartsSection.Personalization.Authorization.Rules.Count
Console.WriteLine(" #{0}:", ai)
Dim aRule As AuthorizationRule = _
webPartsSection.Personalization.Authorization.Rules(ai)
Console.WriteLine(" Verbs=")
Dim verb As String
For Each verb In aRule.Verbs
Console.WriteLine(" * {0}", verb)
Console.WriteLine(" Roles=")
Next
Dim role As String
For Each role In aRule.Roles
Console.WriteLine(" * {0}", role)
Console.WriteLine(" Users=")
Next
Dim user As String
For Each user In aRule.Users
Console.WriteLine(" * {0}", user)
Next
Next