如何programmaticly测试asp.net的位置文件夹权限 [英] How to test asp.net location folder authorization programmaticly

查看:99
本文介绍了如何programmaticly测试asp.net的位置文件夹权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的web.config的位置元素,像这样:

I have an location element in my web.config like so:

<location path="Admin">
    <system.web>
        <authorization>
            <allow roles="Domain\Development"/>
            <deny users="*" />
        </authorization>
    </system.web>
</location>

本工程只允许到该文件夹​​的开发组成员访问。

This works to only allow members of the development group access to this folder.

我不知道是否有一种方法,如果用户有权访问此文件夹的简单测试?

I was wondering if there is a way to simply test if a user has access to this folder?

一种情况是创建菜单项。我只是想隐藏或不渲染页面的链接此文件夹中,如果用户没有适当的权限。

One scenario is creating menu items. I'd simply like to hide or not render links to pages in this folder if the user does not have the proper rights.

有没有办法在code做到这一点。我不希望有硬code在域\\开发成员的支票,而我想使用asp.net来告诉我,如果这个当前用户具​​有访问权限。

Is there a way to do this in code. I don't want to have to hard code a check for membership in Domain\Development rather I'd like to use asp.net to tell me if this current user has access.

如果规则得到同样有这个在一个地方更为复杂等强制DRY(不要重复自己)这将是很好。
谢谢

This would be nice if the rules get more complicated etc. Also having this in one place enforces DRY (Don't Repeat Yourself). Thanks

推荐答案

通过对<一个href=\"http://stackoverflow.com/questions/1048492/determine-if-user-can-access-the-requested-page\">related问题我找到了答案。呼叫 UrlAuthorizationModule.CheckUrlAccessForPrincipal 。 (文档是<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.security.urlauthorizationmodule.checkurlaccessforprincipal%28VS.90%29.aspx\"相对=nofollow>这里。)你可以给它一个路径和用户(如 Page.User 为当前用户),它会告诉你,如果用户可以访问该路径。

Through a related question I found the answer. Call UrlAuthorizationModule.CheckUrlAccessForPrincipal. (Documentation is here.) You can give it a path and a user (such as Page.User for the current user), and it will tell you if the user can access that path.

我喜欢这整整你提到的理由:你可以把你的访问逻辑在一个地方

I like this for exactly the reason you mentioned: You can put your access logic in one place.

这篇关于如何programmaticly测试asp.net的位置文件夹权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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