AuthorizationRule 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
這個 AuthorizationRule 類別允許你程式化地存取並修改設定檔的該 authorization 區段。 此類別無法獲得繼承。
public ref class AuthorizationRule sealed : System::Configuration::ConfigurationElement
public sealed class AuthorizationRule : System.Configuration.ConfigurationElement
type AuthorizationRule = class
inherit ConfigurationElement
Public NotInheritable Class AuthorizationRule
Inherits ConfigurationElement
- 繼承
範例
以下程式碼範例示範如何使用 AuthorizationRule。
Note
如果你使用 credentials 部分,請務必遵循 ASP.NET 認證 所說明的指引。 為了提升可擴展性與安全性,建議使用外部資料庫來儲存使用者憑證。 欲了解更多關於建置安全 ASP.NET 應用程式的資訊,請參閱 Securing Your ASP.NET Application 及 Building Secure ASP.NET Applications: Authentication, Authorization, and Secure Communication。
// Create an authorization rule object.
AuthorizationRuleAction action =
AuthorizationRuleAction.Deny;
AuthorizationRule authorizationRule =
new System.Web.Configuration.AuthorizationRule(action);
' Create an authorization rule object.
Dim action As AuthorizationRuleAction = _
AuthorizationRuleAction.Deny
Dim authorizationRule = _
New System.Web.Configuration.AuthorizationRule(action)
// 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 類別提供一種程式化的方式,可以存取並修改設定檔的該 authorization 區段。
此類型屬於包含 AuthorizationSection、 AuthorizationRuleCollectionAuthorizationRuleAction 、 及 類型組成的群。
Note
他們 AuthorizationSection 可以在配置階層的任何層級更新配置資訊。
建構函式
| 名稱 | Description |
|---|---|
| AuthorizationRule(AuthorizationRuleAction) |
利用傳遞的物件建立一個新的類別實例 AuthorizationRule 。 |