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 物件。

適用於

另請參閱