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