RoleManagerSection Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Definierar konfigurationsinställningar som används för att stödja rollhanteringsinfrastrukturen för webbprogram. Det går inte att ärva den här klassen.
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
- Arv
Exempel
Det här avsnittet innehåller två kodexempel. Den första visar hur du deklarativt anger värden för flera egenskaper för RoleManagerSection klassen. Den andra visar hur du använder typen RoleManagerSection .
Följande konfigurationsfilexempel visar hur du deklarativt anger värden för flera egenskaper för RoleManagerSection klassen.
<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>
Följande kodexempel visar hur du använder typen 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
Kommentarer
Klassen RoleManagerSection ger ett sätt att programmatiskt komma åt och ändra innehållet i roleManager avsnittet i konfigurationsfilen.
Konstruktorer
| Name | Description |
|---|---|
| RoleManagerSection() |
Initierar en ny instans av RoleManagerSection klassen med hjälp av standardinställningar. |
Egenskaper
| Name | Description |
|---|---|
| CacheRolesInCookie |
Hämtar eller anger ett värde som anger om den aktuella användarens roller cachelagras i en cookie. |
| CookieName |
Hämtar eller anger namnet på den cookie som används för att cachelagrat rollnamn. |
| CookiePath |
Hämtar eller anger den virtuella sökvägen för den cookie som används för att cachelagrat rollnamn. |
| CookieProtection |
Hämtar eller anger den typ av säkerhet som används för att skydda cookien som cachelagrar rollnamn. |
| CookieRequireSSL |
Hämtar eller anger ett värde som anger om cookien som används för att cachelagrar rollnamn kräver en SSL-anslutning (Secure Sockets Layer) för att kunna returneras till servern. |
| CookieSlidingExpiration |
Hämtar eller anger ett värde som anger om cookien som används för att cachelagrat rollnamn ska återställas med jämna mellanrum. |
| CookieTimeout |
Hämtar eller anger antalet minuter innan cookien som används för att cachelagrar rollnamn upphör att gälla. |
| CreatePersistentCookie |
Anger om en sessionsbaserad cookie eller en beständig cookie används för att cachelagrat rollnamn. |
| CurrentConfiguration |
Hämtar en referens till den översta instansen Configuration som representerar konfigurationshierarkin som den aktuella ConfigurationElement instansen tillhör. (Ärvd från ConfigurationElement) |
| DefaultProvider |
Hämtar eller anger namnet på standardprovidern som används för att hantera roller. |
| Domain |
Hämtar eller anger namnet på domänen som är associerad med cookien som används för att cachelagrat rollnamn. |
| ElementInformation |
Hämtar ett ElementInformation objekt som innehåller den icke-anpassningsbara informationen och funktionerna i ConfigurationElement objektet. (Ärvd från ConfigurationElement) |
| ElementProperty |
Hämtar objektet ConfigurationElementProperty som representerar ConfigurationElement själva objektet. (Ärvd från ConfigurationElement) |
| Enabled |
Hämtar eller anger ett värde som anger om funktionen ASP.NET rollhantering är aktiverad. |
| EvaluationContext |
Hämtar ContextInformation-objektet för ConfigurationElement-objektet. (Ärvd från ConfigurationElement) |
| HasContext |
Hämtar ett värde som anger om egenskapen CurrentConfiguration är |
| Item[ConfigurationProperty] |
Hämtar eller anger en egenskap eller ett attribut för det här konfigurationselementet. (Ärvd från ConfigurationElement) |
| Item[String] |
Hämtar eller anger en egenskap, ett attribut eller ett underordnat element i det här konfigurationselementet. (Ärvd från ConfigurationElement) |
| LockAllAttributesExcept |
Hämtar samlingen med låsta attribut. (Ärvd från ConfigurationElement) |
| LockAllElementsExcept |
Hämtar samlingen med låsta element. (Ärvd från ConfigurationElement) |
| LockAttributes |
Hämtar samlingen med låsta attribut. (Ärvd från ConfigurationElement) |
| LockElements |
Hämtar samlingen med låsta element. (Ärvd från ConfigurationElement) |
| LockItem |
Hämtar eller anger ett värde som anger om elementet är låst. (Ärvd från ConfigurationElement) |
| MaxCachedResults |
Hämtar eller anger det maximala antalet roller som ASP.NET cacheminnen i rollcookien. |
| Properties |
Hämtar samlingen med egenskaper. (Ärvd från ConfigurationElement) |
| Providers |
Hämtar ett ProviderSettingsCollection objekt med ProviderSettings element. |
| SectionInformation |
Hämtar ett SectionInformation objekt som innehåller den icke-anpassningsbara informationen och funktionerna i ConfigurationSection objektet. (Ärvd från ConfigurationSection) |
Metoder
| Name | Description |
|---|---|
| DeserializeElement(XmlReader, Boolean) |
Läser XML från konfigurationsfilen. (Ärvd från ConfigurationElement) |
| DeserializeSection(XmlReader) |
Läser XML från konfigurationsfilen. (Ärvd från ConfigurationSection) |
| Equals(Object) |
Jämför den aktuella ConfigurationElement instansen med det angivna objektet. (Ärvd från ConfigurationElement) |
| GetHashCode() |
Hämtar ett unikt värde som representerar den aktuella ConfigurationElement instansen. (Ärvd från ConfigurationElement) |
| GetRuntimeObject() |
Returnerar ett anpassat objekt när det åsidosättas i en härledd klass. (Ärvd från ConfigurationSection) |
| GetTransformedAssemblyString(String) |
Returnerar den transformerade versionen av det angivna sammansättningsnamnet. (Ärvd från ConfigurationElement) |
| GetTransformedTypeString(String) |
Returnerar den transformerade versionen av det angivna typnamnet. (Ärvd från ConfigurationElement) |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| Init() |
Anger objektets ConfigurationElement ursprungliga tillstånd. (Ärvd från ConfigurationElement) |
| InitializeDefault() |
Används för att initiera en standarduppsättning med värden för ConfigurationElement objektet. (Ärvd från ConfigurationElement) |
| IsModified() |
Anger om det här konfigurationselementet har ändrats sedan det senast sparades eller lästes in när det implementerades i en härledd klass. (Ärvd från ConfigurationSection) |
| IsReadOnly() |
Hämtar ett värde som anger om objektet ConfigurationElement är skrivskyddat. (Ärvd från ConfigurationElement) |
| ListErrors(IList) |
Lägger till felen invalid-property i det här ConfigurationElement objektet, och i alla underelement, i den överförda listan. (Ärvd från ConfigurationElement) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| OnDeserializeUnrecognizedAttribute(String, String) |
Hämtar ett värde som anger om ett okänt attribut påträffas under deserialiseringen. (Ärvd från ConfigurationElement) |
| OnDeserializeUnrecognizedElement(String, XmlReader) |
Hämtar ett värde som anger om ett okänt element påträffas under deserialiseringen. (Ärvd från ConfigurationElement) |
| OnRequiredPropertyNotFound(String) |
Utlöser ett undantag när en obligatorisk egenskap inte hittas. (Ärvd från ConfigurationElement) |
| PostDeserialize() |
Anropas efter deserialisering. (Ärvd från ConfigurationElement) |
| PreSerialize(XmlWriter) |
Anropas före serialisering. (Ärvd från ConfigurationElement) |
| Reset(ConfigurationElement) |
Återställer objektets interna tillstånd ConfigurationElement , inklusive låsen och egenskapssamlingarna. (Ärvd från ConfigurationElement) |
| ResetModified() |
Återställer värdet för metoden till IsModified() när den |
| SerializeElement(XmlWriter, Boolean) |
Skriver innehållet i det här konfigurationselementet till konfigurationsfilen när det implementeras i en härledd klass. (Ärvd från ConfigurationElement) |
| SerializeSection(ConfigurationElement, String, ConfigurationSaveMode) |
Skapar en XML-sträng som innehåller en icke-komprimerad vy av ConfigurationSection objektet som ett enda avsnitt för att skriva till en fil. (Ärvd från ConfigurationSection) |
| SerializeToXmlElement(XmlWriter, String) |
Skriver de yttre taggarna för det här konfigurationselementet till konfigurationsfilen när det implementeras i en härledd klass. (Ärvd från ConfigurationElement) |
| SetPropertyValue(ConfigurationProperty, Object, Boolean) |
Anger en egenskap till det angivna värdet. (Ärvd från ConfigurationElement) |
| SetReadOnly() |
Anger egenskapen IsReadOnly() för ConfigurationElement objektet och alla underelement. (Ärvd från ConfigurationElement) |
| ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName) |
Anger om det angivna elementet ska serialiseras när konfigurationsobjekthierarkin serialiseras för den angivna målversionen av .NET Framework. (Ärvd från ConfigurationSection) |
| ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement) |
Anger om den angivna egenskapen ska serialiseras när konfigurationsobjekthierarkin serialiseras för den angivna målversionen av .NET Framework. (Ärvd från ConfigurationSection) |
| ShouldSerializeSectionInTargetVersion(FrameworkName) |
Anger om den aktuella ConfigurationSection-instansen ska serialiseras när konfigurationsobjekthierarkin serialiseras för den angivna målversionen av .NET Framework. (Ärvd från ConfigurationSection) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |
| Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode) |
Ändrar objektet ConfigurationElement för att ta bort alla värden som inte ska sparas. (Ärvd från ConfigurationElement) |