AuthorizationSection.Rules Property

Definition

C#
[System.Configuration.ConfigurationProperty("", IsDefaultCollection=true)]
public System.Web.Configuration.AuthorizationRuleCollection Rules { get; }

Property Value

Gets the AuthorizationRuleCollection of AuthorizationRule rules defined by the AuthorizationSection.

Attributes

Examples

The following code example shows how to use the Rules.

C#
 // Using the AuthorizationRuleCollection Add method.

 // Set the action property.
 authorizationRule.Action = 
    AuthorizationRuleAction.Allow;
 // Define the new rule to add to the collection.
 authorizationRule.Users.Add("userName");
 authorizationRule.Roles.Add("admin");
 authorizationRule.Verbs.Add("POST");

 // Add the new rule to the collection.
 authorizationSection.Rules.Add(authorizationRule);

Remarks

The Rules collection returned by this method does not refer to any actual element in the underlying configuration file. It is a construct that allows easy access to the rules it contains. This is a common pattern for handling the elements of a configuration file.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also