jua*_*uan 3 security asp.net-membership web-config roles
我想通过web.config文件中的授权部分来使用基于角色的安全性.
使用Membership,我的应用程序将允许创建新角色,因此,他们可以访问的页面需要动态设置.
我可以以编程方式更改web.config中的此部分来管理它吗?如果是这样,怎么样?
using System.Configuration;
using System.Web.Configuration;
Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
AuthorizationSection section = (AuthorizationSection)config.GetSection("system.web/authorization");
AuthorizationRule rule = new AuthorizationRule(AuthorizationRuleAction.Allow);
rule.Roles.Add("admins");
section.Rules.Add(rule);
config.Save();
Run Code Online (Sandbox Code Playgroud)
Imports System.Configuration
Imports System.Web.Configuration
Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
Dim section As AuthorizationSection = CType(config.GetSection("system.web/authorization"), AuthorizationSection)
Dim rule As New AuthorizationRule(AuthorizationRuleAction.Allow)
rule.Roles.Add("admins")
section.Rules.Add(rule)
config.Save()
Run Code Online (Sandbox Code Playgroud)
ASP.NET需要web.config写权限才能工作,所以要小心.
归档时间: |
|
查看次数: |
2709 次 |
最近记录: |