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.
注释
如果使用 credentials 部分,请务必遵循ASP.NET 身份验证中介绍的准则。 为了获得可伸缩性和更好的安全功能,建议使用外部数据库来存储用户的凭据。 有关生成安全 ASP.NET 应用程序的详细信息,请参阅 Securing your ASP.NET Application and 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类型、类型和 AuthorizationRuleCollection类型的组的 AuthorizationRuleAction 一部分。
注释
可以在 AuthorizationSection 配置层次结构中的任何级别更新配置信息。
构造函数
| 名称 | 说明 |
|---|---|
| AuthorizationRule(AuthorizationRuleAction) |
使用传递的对象创建类的新实例 AuthorizationRule 。 |