共用方式為


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

適用於

另請參閱