加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 授权web.config中的属性对授权节点

发布时间:2020-12-15 19:02:44 所属栏目:asp.Net 来源:网络整理
导读:我知道我可以使用web.config中的授权标签限制对ASP.NET MVC 3应用程序的访问 authentication mode="Windows"/authentication roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider" / authorization allow roles="MyDomainMyGroup"
我知道我可以使用web.config中的授权标签限制对ASP.NET MVC 3应用程序的访问
   <authentication mode="Windows"></authentication>
    <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider" />
    <authorization>
      <allow roles="MyDomainMyGroup" />
      <deny users="*" />
      <deny users="?" />
    </authorization>

或使用[Authorize()]属性(甚至使用自定义Authorize属性)来装饰控制器基类,

[AdminOnly]
public class BaseController : Controller{}

问题是:他们是替代的和等同的方法吗?我应该总是使用一种方法而不是另一种方法?我应该记住哪些要素?

解决方法

I know I can restrict the access to an ASP.NET MVC 3 application using the authorization tag in web.config

不,不要在ASP.NET MVC中使用.

The question is: are they alternative and equivalent approaches?

不,他们是不可替代的.您不应使用< authorization>标签在ASP.NET MVC应用程序中的web.config中,因为它基于路径,而MVC与控制器操作和路由协同工作.在ASP.NET MVC中进行授权的正确方法是使用[Authorize]属性.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读