Επεξεργασία

Κοινή χρήση μέσω


AuthorizationRuleCollection.Add(AuthorizationRule) Method

Definition

Adds a AuthorizationRule object to the collection.

public:
 void Add(System::Web::Configuration::AuthorizationRule ^ rule);
public void Add (System.Web.Configuration.AuthorizationRule rule);
member this.Add : System.Web.Configuration.AuthorizationRule -> unit
Public Sub Add (rule As AuthorizationRule)

Parameters

rule
AuthorizationRule

The AuthorizationRule object to add to the collection.

Exceptions

The AuthorizationRule object already exists in the collection, or the collection is read-only.

Examples

The following code example shows how to use the Add method.

 // 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);
' 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 collection must not already contain the AuthorizationRule object you are adding.

Applies to

See also