在web.config中访问授权信息 [英] Accessing authorization information in web.config

查看:200
本文介绍了在web.config中访问授权信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个自定义的角色提供我需要的编程访问存储在web.config中的授权信息。
该网站的某些部分只能由某些角色访问。我想找出哪些角色可以访问一个网页,并/或有一定的作用可以访问哪些页面。

I'm writing a custom role provider and I need programmatic access the authorization information stored in the web.config. Certain section of the site are only accessible by certain roles. I would like to find out which roles can access a page and/or which page a certain role can access.

我似乎无法推测这一个。

I can't seem to figure this one out.

推荐答案

您可以访问如的ConnectionStrings,的AppSettings和其他定义的值在web.config中通过System.Web.Security命名空间WebConfigurationManager类存储的任何信息。

You can access any information stored such as ConnectionStrings,AppSettings and other defined values in web.config by WebConfigurationManager class in System.Web.Security namespace.

假设你已经定义和授权部分为:

Let's say you have defined and authorization section as:

<system.web>
<authorization>
  <allow roles="admin,moderator" />
  <deny users="?" />
</authorization></system.web>

您刚刚创建的部分意味着谁拥有用户的管理和/或主持人角色可以访问内的网页,并拒绝每个人(匿名)谁试图访问没有登录信息。

The section you just created means users who has admin and/or moderator roles can access pages within and deny everyone (anonymous) who attempts to access without login information.

在为刚刚叫出WebConfigurationManager的GetSection方法

In order to that just call out WebConfigurationManager's GetSection method as

AuthorizationSection auth = WebConfigurationManager.GetSection("system.web/authorization") as AuthorizationSection;

AuthorizationSection教室将给你
规则收藏这是$ P $你要寻找的。pcisely什么

AuthorizationSection class will give you Rules collection which is precisely what you're looking for.

这篇关于在web.config中访问授权信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆