AuthorizationRuleCollection.Add(AuthorizationRule) 方法

定义

AuthorizationRule 对象添加到集合中。

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)

参数

rule
AuthorizationRule

要添加到集合的 AuthorizationRule 对象。

例外

集合中已经存在该 AuthorizationRule 对象,或此集合为只读。

示例

下面的代码示例说明如何使用 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)

注解

集合不得已包含 AuthorizationRule 要添加的对象。

适用于

另请参阅