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

前端之家收集整理的这篇文章主要介绍了asp.net – 授权web.config中的属性对授权节点前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我知道我可以使用web.config中的授权标签限制对ASP.NET MVC 3应用程序的访问
   <authentication mode="Windows"></authentication>
    <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider" />
    <authorization>
      <allow roles="MyDomain\MyGroup" />
      <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]属性.

原文链接:https://www.f2er.com/aspnet/246610.html

猜你在找的asp.Net相关文章