asp.net – 在我的代码隐藏类中,如何检索授权角色?
我在web.config中有以下内容:
<location path="RestrictedPage.aspx"> <system.web> <authorization> <allow roles="Group1Admin,Group3Admin,Group7Admin"/> <deny users="*"/> </authorization> </system.web> </location> 在RestrictedPage.aspx.cs中,如何检索包含Group1Admin,Group3Admin和Group7Admin的允许角色集合? 这就是为什么我问: web.config正在处理页面的授权.这很好.但是我将会有几个这样的页面(比如RestrictedPage.aspx,RestrictedPage2.aspx,RestrictedPage3.aspx).这些页面中的每一个都将在其上进行自定义webcontrol.每个页面都有不同的允许角色.我的webcontrol有一个下拉列表.下拉列表中的选项取决于用户角色与页面允许角色的交集. 如下所述,使用XPath搜索web.config可能会有效.我只是希望有更多的框架.有点像SiteMap.当我在我的web.sitemap中放置角色时,我可以使用SiteMap.CurrentNode.Roles抓取它们(我的网站使用的是Windows身份验证,所以我不能使用web.sitemap进行安全修整,而是宁愿只保留一个角色文件). 解决方法// set the configuration path to your config file string configPath = "??"; Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath); // Get the object related to the <identity> section. AuthorizationSection section = (AuthorizationSection)config.GetSection("system.web/authorization"); 从section对象获取AuthorizationRuleCollection对象,然后在其中提取角色. 注意:您可能需要稍微修改该部分的路径,因为您从“location path =”RestrictedPage.aspx“”开始,我没有尝试这种情况. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ASP.NET Core / MVC 6 ViewModel中的依赖注入(DI)
- 玩转VSCode-完整构建VSCode开发调试环境
- asp.net-mvc-3 – 在MVC3中对Webgrid行进行内联编辑
- asp.net-mvc – 想从mvc使用index.html
- asp.net-core – 程序集中找不到入口点’Microsoft.EntityF
- asp.net – 验证嵌套的ViewModels
- ASP.net webforms中的异步页面处理示例(.NET 2.0)
- asp.net-mvc – 使用View.Render方法将MVC视图转换为字符串
- asp.net – WebFormsMVP的缺点?
- Asp.Net:在iis中调试网站
- asp.net – 在visual studio中的同一解决方案中运
- asp.net-mvc – Ninject如何在ASP.NET MVC中创建
- asp.net-mvc-4 – HttpResponseException
- ASP.NET MVC:Application_Start和Url.Action
- Asp.net 5 MVC 6,添加facebook电子邮件的权限
- .net – 具有实体框架的存储库模式
- asp.net – 冻结标题,滚动GridView
- asp.net – applicationSettings和Web.config
- [你必须知道的.NET] 第五回:深入浅出关键字---把
- asp.net – 多个选择列表框而不按CTRL