WebPartsPersonalization 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
允許您指定個人化提供者,並設定個人化授權。 此類別無法獲得繼承。
public ref class WebPartsPersonalization sealed : System::Configuration::ConfigurationElement
public sealed class WebPartsPersonalization : System.Configuration.ConfigurationElement
type WebPartsPersonalization = class
inherit ConfigurationElement
Public NotInheritable Class WebPartsPersonalization
Inherits ConfigurationElement
- 繼承
範例
這個範例示範如何針對 區段的 webParts
數個屬性以宣告方式指定值,這也可以當做 類別的成員 WebPartsPersonalization 來存取。
下列組態檔範例示範如何以宣告方式 webParts
指定 區段的值。
<system.web>
<webParts>
<personalization
defaultProvider="AspNetSqlPersonalizationProvider">
<!-- Providers may only be defined at the
application level -->
<providers>
<add name="AspNetSqlPersonalizationProvider"
type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider"
connectionStringName="LocalSqlServer"
applicationName="/" />
</providers>
<authorization>
<deny users="*" verbs="enterSharedScope" />
<allow users="*" verbs="modifyState" />
</authorization>
</personalization>
</webParts>
</system.web>
下列程式代碼範例示範如何使用 WebPartsPersonalization 類別。
此程式代碼範例是針對 類別提供的較大範例的 WebPartsSection 一部分。
// 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
備註
WebPartsPersonalization 提供網頁元件個人化選項的組態支援,例如個人化提供者和個人化授權。
建構函式
WebPartsPersonalization() |
使用預設值初始化 WebPartsPersonalization 類別的新執行個體。 |