RoleManagerSection 类

定义

定义用于支持 Web 应用程序的角色管理基础结构的配置设置。 此类不能被继承。

public ref class RoleManagerSection sealed : System::Configuration::ConfigurationSection
public sealed class RoleManagerSection : System.Configuration.ConfigurationSection
type RoleManagerSection = class
    inherit ConfigurationSection
Public NotInheritable Class RoleManagerSection
Inherits ConfigurationSection
继承

示例

本部分提供两个代码示例。 第一个演示如何以声明方式指定类的 RoleManagerSection 多个属性的值。 第二个演示了如何使用类型 RoleManagerSection

以下配置文件示例演示如何以声明方式指定类的 RoleManagerSection 多个属性的值。

<system.web>  
  <roleManager   
    enabled="false"   
    cacheRolesInCookie="false"   
    cookieName=".ASPXROLES" cookieTimeout="30"  
    cookiePath="/" cookieRequireSSL="false"  
    cookieSlidingExpiration="true" createPersistentCookie="false"  
    cookieProtection="All"   
    defaultProvider="AspNetSqlRoleProvider"  
    maxCachedResults="25"  >  
    <providers>  
      <add   
        name="AspNetSqlRoleProvider"  
        connectionStringName="LocalSqlServer"   
        applicationName="/"  
        type="System.Web.Security.SqlRoleProvider, System.Web,  
          Version=2.0.3600.0, Culture=neutral,  
          PublicKeyToken=b03f5f7f11d50a3a" />  
      <add   
        name="AspNetWindowsTokenRoleProvider"   
        applicationName="/"  
        type="System.Web.Security.WindowsTokenRoleProvider, System.Web,   
          Version=2.0.3600.0, Culture=neutral,   
          PublicKeyToken=b03f5f7f11d50a3a" />  
    </providers>  
  </roleManager>  
</system.web>  

下面的代码示例演示如何使用该 RoleManagerSection 类型。

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Web;
using System.Web.Configuration;

#endregion

namespace Samples.Aspnet.SystemWebConfiguration
{
  class UsingRoleManagerSection
  {
    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.
        RoleManagerSection configSection =
          (RoleManagerSection)config.GetSection("system.web/roleManager");

        // Display title and info.
        Console.WriteLine("ASP.NET Configuration Info");
        Console.WriteLine();

        // Display Config details.
        Console.WriteLine("File Path: {0}",
          config.FilePath);
        Console.WriteLine("Section Path: {0}",
          configSection.SectionInformation.Name);

        // Display CacheRolesInCookie property.
        Console.WriteLine("CacheRolesInCookie: {0}",
          configSection.CacheRolesInCookie);

        // Set CacheRolesInCookie property.
        configSection.CacheRolesInCookie = false;

        // Display CookieName property.
        Console.WriteLine("CookieName: {0}", configSection.CookieName);

        // Set CookieName property.
        configSection.CookieName = ".ASPXROLES";

        // Display CookiePath property.
        Console.WriteLine("CookiePath: {0}", configSection.CookiePath);

        // Set CookiePath property.
        configSection.CookiePath = "/";

        // Display CookieProtection property.
        Console.WriteLine("CookieProtection: {0}",
          configSection.CookieProtection);

        // Set CookieProtection property.
        configSection.CookieProtection =
          System.Web.Security.CookieProtection.All;

        // Display CookieRequireSSL property.
        Console.WriteLine("CookieRequireSSL: {0}",
          configSection.CookieRequireSSL);

        // Set CookieRequireSSL property.
        configSection.CookieRequireSSL = false;

        // Display CookieSlidingExpiration property.
        Console.WriteLine("CookieSlidingExpiration: {0}",
          configSection.CookieSlidingExpiration);

        // Set CookieSlidingExpiration property.
        configSection.CookieSlidingExpiration = true;

        // Display CookieTimeout property.
        Console.WriteLine("CookieTimeout: {0}", configSection.CookieTimeout);

        // Set CookieTimeout property.
        configSection.CookieTimeout = TimeSpan.FromMinutes(30);

        // Display CreatePersistentCookie property.
        Console.WriteLine("CreatePersistentCookie: {0}",
          configSection.CreatePersistentCookie);

        // Set CreatePersistentCookie property.
        configSection.CreatePersistentCookie = false;

        // Display DefaultProvider property.
        Console.WriteLine("DefaultProvider: {0}",
          configSection.DefaultProvider);

        // Set DefaultProvider property.
        configSection.DefaultProvider = "AspNetSqlRoleProvider";

        // Display Domain property.
        Console.WriteLine("Domain: {0}", configSection.Domain);

        // Set Domain property.
        configSection.Domain = "";

        // Display Enabled property.
        Console.WriteLine("Enabled: {0}", configSection.Enabled);

        // Set Enabled property.
        configSection.Enabled = false;

        // Display the number of Providers
        Console.WriteLine("Providers Collection Count: {0}",
          configSection.Providers.Count);

        // Display elements of the Providers collection property.
        foreach (ProviderSettings providerItem in configSection.Providers)
        {
          Console.WriteLine();
          Console.WriteLine("Provider Details:");
          Console.WriteLine("Name: {0}", providerItem.Name);
          Console.WriteLine("Type: {0}", providerItem.Type);
        }

        // Update if not locked.
        if (!configSection.SectionInformation.IsLocked)
        {
          config.Save();
          Console.WriteLine("** Configuration updated.");
        }
        else
        {
          Console.WriteLine("** Could not update, section is locked.");
        }
      }

      catch (Exception e)
      {
        // Unknown error.
        Console.WriteLine(e.ToString());
      }

      // Display and wait
      Console.ReadLine();
    }
  }
}
Imports System.Collections.Generic
Imports System.Text
Imports System.Configuration
Imports System.Web
Imports System.Web.Configuration

Namespace Samples.Aspnet.SystemWebConfiguration
  Class UsingRoleManagerSection
    Public Shared Sub Main()
      Try
        ' Set the path of the config file.
        Dim configPath As String = ""

        ' Get the Web application configuration object.
        Dim config As System.Configuration.Configuration = _
         System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(configPath)

        ' Get the section related object.
        Dim configSection As System.Web.Configuration.RoleManagerSection = _
         CType(config.GetSection("system.web/roleManager"), _
         System.Web.Configuration.RoleManagerSection)

        ' Display title and info.
        Console.WriteLine("ASP.NET Configuration Info")
        Console.WriteLine()

        ' Display Config details.
        Console.WriteLine("File Path: {0}", config.FilePath)
        Console.WriteLine("Section Path: {0}", configSection.SectionInformation.Name)

        ' Display CacheRolesInCookie property.
        Console.WriteLine("CacheRolesInCookie: {0}", _
         configSection.CacheRolesInCookie)

        ' Set CacheRolesInCookie property.
        configSection.CacheRolesInCookie = False

        ' Display CookieName property.
        Console.WriteLine("CookieName: {0}", configSection.CookieName)

        ' Set CookieName property.
        configSection.CookieName = ".ASPXROLES"

        ' Display CookiePath property.
        Console.WriteLine("CookiePath: {0}", configSection.CookiePath)

        ' Set CookiePath property.
        configSection.CookiePath = "/"

        ' Display CookieProtection property.
        Console.WriteLine("CookieProtection: {0}", _
         configSection.CookieProtection)

        ' Set CookieProtection property.
        configSection.CookieProtection = _
         System.Web.Security.CookieProtection.All

        ' Display CookieRequireSSL property.
        Console.WriteLine("CookieRequireSSL: {0}", _
         configSection.CookieRequireSSL)

        ' Set CookieRequireSSL property.
        configSection.CookieRequireSSL = False

        ' Display CookieSlidingExpiration property.
        Console.WriteLine("CookieSlidingExpiration: {0}", _
         configSection.CookieSlidingExpiration)

        ' Set CookieSlidingExpiration property.
        configSection.CookieSlidingExpiration = True

        ' Display CookieTimeout property.
        Console.WriteLine("CookieTimeout: {0}", configSection.CookieTimeout)

        ' Set CookieTimeout property.
        configSection.CookieTimeout = TimeSpan.FromMinutes(30)

        ' Display CreatePersistentCookie property.
        Console.WriteLine("CreatePersistentCookie: {0}", _
         configSection.CreatePersistentCookie)

        ' Set CreatePersistentCookie property.
        configSection.CreatePersistentCookie = False

        ' Display DefaultProvider property.
        Console.WriteLine("DefaultProvider: {0}", _
         configSection.DefaultProvider)

        ' Set DefaultProvider property.
        configSection.DefaultProvider = "AspNetSqlRoleProvider"

        ' Display Domain property.
        Console.WriteLine("Domain: {0}", configSection.Domain)

        ' Set Domain property.
        configSection.Domain = ""

        ' Display Enabled property.
        Console.WriteLine("Enabled: {0}", configSection.Enabled)

        ' Set CookieName property.
        configSection.Enabled = False

        ' Display the number of Providers
        Console.WriteLine("Providers Collection Count: {0}", _
         configSection.Providers.Count)

        ' Display elements of the Providers collection property.
        For Each providerItem As ProviderSettings In configSection.Providers()
          Console.WriteLine()
          Console.WriteLine("Provider Details:")
          Console.WriteLine("Name: {0}", providerItem.Name)
          Console.WriteLine("Type: {0}", providerItem.Type)
        Next

        ' Update if not locked.
        If Not configSection.SectionInformation.IsLocked Then
          config.Save()
          Console.WriteLine("** Configuration updated.")
        Else
          Console.WriteLine("** Could not update, section is locked.")
        End If

      Catch e As Exception
        ' Unknown error.
        Console.WriteLine(e.ToString())
      End Try

      ' Display and wait
      Console.ReadLine()
    End Sub
  End Class
End Namespace

注解

RoleManagerSection 类提供了一种以编程方式访问和修改配置文件节内容 roleManager 的方法。

构造函数

RoleManagerSection()

使用默认设置初始化 RoleManagerSection 类的新实例。

属性

CacheRolesInCookie

获取或设置一个值,该值指示当前用户的角色是否已缓存在某个 Cookie 中。

CookieName

获取或设置用于缓存角色名称的 Cookie 的名称。

CookiePath

获取或设置用于缓存角色名称的 Cookie 的虚拟路径。

CookieProtection

获取或设置用于保护缓存角色名称的 Cookie 的安全类型。

CookieRequireSSL

获取或设置一个值,该值指示用于缓存角色名称的 Cookie 是否需要一个安全套接字层 (SSL) 连接才能被返回到服务器。

CookieSlidingExpiration

获取或设置一个值,该值指示是否定期重置用于缓存角色名称的 Cookie。

CookieTimeout

获取或设置用于缓存角色名称的 Cookie 过期之前的分钟数。

CreatePersistentCookie

指示是使用基于会话的 Cookie 还是使用持久性 Cookie 来缓存角色名称。

CurrentConfiguration

获取对顶级 Configuration 实例的引用,该实例表示当前 ConfigurationElement 实例所属的配置层次结构。

(继承自 ConfigurationElement)
DefaultProvider

获取或设置用于管理角色的默认提供程序的名称。

Domain

获取或设置与用于缓存角色名称的 Cookie 关联的域的名称。

ElementInformation

获取包含 ConfigurationElement 对象的不可自定义的信息和功能的 ElementInformation 对象。

(继承自 ConfigurationElement)
ElementProperty

获取表示 ConfigurationElement 对象本身的 ConfigurationElementProperty 对象。

(继承自 ConfigurationElement)
Enabled

获取或设置一个值,该值指示是否启用 ASP.NET 角色管理功能。

EvaluationContext

获取 ConfigurationElement 对象的 ContextInformation 对象。

(继承自 ConfigurationElement)
HasContext

获取一个值,该值指示 CurrentConfiguration 属性是否为 null

(继承自 ConfigurationElement)
Item[ConfigurationProperty]

获取或设置此配置元素的属性或特性。

(继承自 ConfigurationElement)
Item[String]

获取或设置此配置元素的属性、特性或子元素。

(继承自 ConfigurationElement)
LockAllAttributesExcept

获取被锁定的特性的集合。

(继承自 ConfigurationElement)
LockAllElementsExcept

获取被锁定的元素的集合。

(继承自 ConfigurationElement)
LockAttributes

获取被锁定的特性的集合。

(继承自 ConfigurationElement)
LockElements

获取被锁定的元素的集合。

(继承自 ConfigurationElement)
LockItem

获取或设置一个值,该值指示是否已锁定该元素。

(继承自 ConfigurationElement)
MaxCachedResults

获取或设置 ASP.NET 在角色 Cookie 中缓存的角色的最大数目。

Properties

获取属性的集合。

(继承自 ConfigurationElement)
Providers

获取 ProviderSettingsCollection 元素的 ProviderSettings 对象。

SectionInformation

获取一个 SectionInformation 对象,该对象包含 ConfigurationSection 对象的不可自定义的信息和功能。

(继承自 ConfigurationSection)

方法

DeserializeElement(XmlReader, Boolean)

从配置文件读取 XML。

(继承自 ConfigurationElement)
DeserializeSection(XmlReader)

从配置文件读取 XML。

(继承自 ConfigurationSection)
Equals(Object)

将当前的 ConfigurationElement 实例与指定的对象进行比较。

(继承自 ConfigurationElement)
GetHashCode()

获取表示当前 ConfigurationElement 实例的唯一值。

(继承自 ConfigurationElement)
GetRuntimeObject()

在派生的类中重写时返回自定义对象。

(继承自 ConfigurationSection)
GetTransformedAssemblyString(String)

返回指定程序集名称的转换版本。

(继承自 ConfigurationElement)
GetTransformedTypeString(String)

返回指定类型名称的转换版本。

(继承自 ConfigurationElement)
GetType()

获取当前实例的 Type

(继承自 Object)
Init()

ConfigurationElement 对象设置为其初始状态。

(继承自 ConfigurationElement)
InitializeDefault()

用于初始化 ConfigurationElement 对象的默认值集。

(继承自 ConfigurationElement)
IsModified()

指示自上次在派生类中实现此配置元素时保存或加载以来是否对其进行过修改。

(继承自 ConfigurationSection)
IsReadOnly()

获取一个值,该值指示 ConfigurationElement 对象是否为只读。

(继承自 ConfigurationElement)
ListErrors(IList)

将此 ConfigurationElement 对象以及所有子元素中无效属性的错误添加到传递的列表中。

(继承自 ConfigurationElement)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
OnDeserializeUnrecognizedAttribute(String, String)

获取一个值,该值指示反序列化过程中是否遇到未知特性。

(继承自 ConfigurationElement)
OnDeserializeUnrecognizedElement(String, XmlReader)

获取一个值,该值指示反序列化过程中是否遇到未知元素。

(继承自 ConfigurationElement)
OnRequiredPropertyNotFound(String)

找不到所需属性时引发异常。

(继承自 ConfigurationElement)
PostDeserialize()

反序列化后调用。

(继承自 ConfigurationElement)
PreSerialize(XmlWriter)

在序列化之前调用。

(继承自 ConfigurationElement)
Reset(ConfigurationElement)

重置 ConfigurationElement 对象的内部状态,包括锁和属性集合。

(继承自 ConfigurationElement)
ResetModified()

在派生类中实现时,将 IsModified() 方法的值重置为 false

(继承自 ConfigurationSection)
SerializeElement(XmlWriter, Boolean)

当在派生类中实现后,将此配置元素的内容写入配置文件。

(继承自 ConfigurationElement)
SerializeSection(ConfigurationElement, String, ConfigurationSaveMode)

创建一个包含 ConfigurationSection 对象的分离视图的 XML 字符串,作为单独的节写入到文件中。

(继承自 ConfigurationSection)
SerializeToXmlElement(XmlWriter, String)

当在派生类中实现后,将此配置元素的外部标记写入配置文件。

(继承自 ConfigurationElement)
SetPropertyValue(ConfigurationProperty, Object, Boolean)

将属性设置为指定值。

(继承自 ConfigurationElement)
SetReadOnly()

设置 ConfigurationElement 对象及所有子元素的 IsReadOnly() 属性。

(继承自 ConfigurationElement)
ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName)

指示当为指定目标版本的.NET Framework序列化配置对象层次结构时,是否应序列化指定的元素。

(继承自 ConfigurationSection)
ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement)

指示当为指定的目标版本的.NET Framework序列化配置对象层次结构时,是否应序列化指定的属性。

(继承自 ConfigurationSection)
ShouldSerializeSectionInTargetVersion(FrameworkName)

指示在为指定目标版本的.NET Framework序列化配置对象层次结构时,是否应序列化当前ConfigurationSection实例。

(继承自 ConfigurationSection)
ToString()

返回表示当前对象的字符串。

(继承自 Object)
Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode)

修改 ConfigurationElement 对象以移除所有不应该保存的值。

(继承自 ConfigurationElement)

适用于

另请参阅