本文整理汇总了C#中System.Configuration.ConfigurationLockCollection类的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationLockCollection类的具体用法?C# ConfigurationLockCollection怎么用?C# ConfigurationLockCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationLockCollection类属于System.Configuration命名空间,在下文中一共展示了ConfigurationLockCollection类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
#region Using directives
using System;
using System.Configuration;
using System.Web.Configuration;
using System.Collections;
using System.Text;
#endregion
namespace Samples.Aspnet.SystemWebConfiguration
{
class UsingConfigurationLockCollection
{
static void Main(string[] args)
{
try
{
// Set the path of the config file.
string configPath = "";
// Get the Web application configuration object.
Configuration config =
WebConfigurationManager.OpenWebConfiguration(configPath);
// Get the section related object.
AnonymousIdentificationSection configSection =
(AnonymousIdentificationSection)config.GetSection
("system.web/anonymousIdentification");
// Display title and info.
Console.WriteLine("Configuration Info");
Console.WriteLine();
// Display Config details.
Console.WriteLine("File Path: {0}",
config.FilePath);
Console.WriteLine("Section Path: {0}",
configSection.SectionInformation.Name);
Console.WriteLine();
// Create a ConfigurationLockCollection object.
ConfigurationLockCollection lockedAttribList;
lockedAttribList = configSection.LockAttributes;
// Add an attribute to the lock collection.
if (!lockedAttribList.Contains("enabled"))
{
lockedAttribList.Add("enabled");
}
if (!lockedAttribList.Contains("cookieless"))
{
lockedAttribList.Add("cookieless");
}
// Count property.
Console.WriteLine("Collection Count: {0}",
lockedAttribList.Count);
// AttributeList method.
Console.WriteLine("AttributeList: {0}",
lockedAttribList.AttributeList);
// Contains method.
Console.WriteLine("Contains 'enabled': {0}",
lockedAttribList.Contains("enabled"));
// HasParentElements property.
Console.WriteLine("HasParentElements: {0}",
lockedAttribList.HasParentElements);
// IsModified property.
Console.WriteLine("IsModified: {0}",
lockedAttribList.IsModified);
// IsReadOnly method.
Console.WriteLine("IsReadOnly: {0}",
lockedAttribList.IsReadOnly("enabled"));
// Remove a configuration object
// from the collection.
lockedAttribList.Remove("cookieless");
// Clear the collection.
lockedAttribList.Clear();
// Create an ArrayList to contain
// the property items of the configuration
// section.
ArrayList configPropertyAL = new ArrayList(lockedAttribList.Count);
foreach (PropertyInformation propertyItem in
configSection.ElementInformation.Properties)
{
configPropertyAL.Add(propertyItem.Name.ToString());
}
// Copy the elements of the ArrayList to a string array.
String[] myArr = (String[])configPropertyAL.ToArray(typeof(string));
// Create as a comma delimited list.
string propList = string.Join(",", myArr);
// Lock the items in the list.
lockedAttribList.SetFromList(propList);
}
catch (Exception e)
{
// Unknown error.
Console.WriteLine(e.ToString());
}
// Display and wait.
Console.ReadLine();
}
}
}