Partager via


AuthorizationRuleCollection.Add(AuthorizationRule) Méthode

Définition

Ajoute un objet AuthorizationRule à la 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)

Paramètres

rule
AuthorizationRule

Objet AuthorizationRule à ajouter à la collection.

Exceptions

L'objet AuthorizationRule existe déjà dans la collection ou la collection est en lecture seule.

Exemples

L'exemple de code suivant montre comment utiliser la méthode Add.

 // 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)

Remarques

La collection ne doit pas déjà contenir l’objet AuthorizationRule que vous ajoutez.

S’applique à

Voir aussi