当前位置: 首页>>代码示例>>C#>>正文


C# WebPartsSection类代码示例

本文整理汇总了C#中System.Web.Configuration.WebPartsSection的典型用法代码示例。如果您正苦于以下问题:C# WebPartsSection类的具体用法?C# WebPartsSection怎么用?C# WebPartsSection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WebPartsSection类属于System.Web.Configuration命名空间,在下文中一共展示了WebPartsSection类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Configuration.Provider;
using System.Web.Configuration;

namespace Samples.Aspnet.SystemWebConfiguration
{
    // Accesses the System.Web.Configuration.WebPartsSection
    // members selected by the user.
    class UsingWebPartsSection
    {
        public static void Main()
        {
            // Process the System.Web.Configuration.WebPartsSectionobject.
            try
            {
                // Get the Web application configuration.
                Configuration configuration = 
                    WebConfigurationManager.OpenWebConfiguration("/aspnet");

                // Get the section.
                WebPartsSection webPartsSection = (WebPartsSection) 
                    configuration.Sections["system.web/webParts"];
// Add a Transfomer Info Object to the collection using a constructor.
webPartsSection.Transformers.Add(new TransformerInfo(
    "RowToFilterTransformer",
    "MyCustomTransformers.RowToFilterTransformer"));

// Show all TransformerInfo objects in the collection.
for (int ti = 0;
    ti < webPartsSection.Personalization.Providers.Count; ti++)
{
    Console.WriteLine("  #{0} Name={1} Type={2}", ti,
        webPartsSection.Transformers[ti].Name,
        webPartsSection.Transformers[ti].Type);
}

// Remove a TransformerInfo object by name.
webPartsSection.Transformers.Remove("RowToFilterTransformer");

// Remove a TransformerInfo object by index.
webPartsSection.Transformers.RemoveAt(0);

// Clear all TransformerInfo objects from the collection.
webPartsSection.Transformers.Clear();

// 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);
}


                // Update if not locked.
                if (! webPartsSection.IsReadOnly())
                {
                    configuration.Save();
                    Console.WriteLine("** Configuration updated.");
                }
                else
                {
                    Console.WriteLine("** Could not update, section is locked.");
                }
            }
            catch (System.ArgumentException e)
            {
                // Unknown error.
                Console.WriteLine(
                    "A invalid argument exception detected in UsingWebPartsSection Main. Check your");
                Console.WriteLine("command line for errors.");
            }
        }
    } // UsingWebPartsSection class end.
} // Samples.Aspnet.SystemWebConfiguration namespace end.
开发者ID:.NET开发者,项目名称:System.Web.Configuration,代码行数:122,代码来源:WebPartsSection


注:本文中的System.Web.Configuration.WebPartsSection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。