如何限制访问控制器或MVC文件夹? [英] How to limit the access to a Controller or a folder in MVC?
问题描述
我使用Asp.Net MVC 3,C#与ApplicationServices会员(标准的方式起诉MS SQL 2008 DB)。一起
我的文件夹结构
控制器
- PageAController.cs
- ADMIN
- PageBController.cs
我有一个用户使用的一些作用AdminRole,一些没有关联的规则(匿名者)。
我想的 DENY 访问特定的控制器和显示的登录页 PageAController.cs
和所有控制器的文件夹中的管理
的用户已经不是AdminRole相关联。
- 什么的方式去?
- 请我需要设置的Web.Config ......怎么样?
希望这有助于
<一个href=\"http://blogs.msdn.com/b/rickandy/archive/2011/05/02/securing-your-asp-net-mvc-3-application.aspx\"相对=nofollow>使用AuthorizeAttribute
您不能使用路由或web.config文件中,以确保你的MVC
应用。以确保您的MVC应用程序唯一支持的方法是
到[授权]属性适用于每个控制器和动作
方法(除了登录/注册方法)。使安全
根据当前区域决定,这是一个非常糟糕的事情,并会打开
你的应用程序的漏洞
块引用>[授权(角色=AdminRole)]
公共类PageAController
{}[授权(角色=AdminRole,AnotherRole)]
公共类PageBController
{}I use Asp.Net MVC 3, C# together with ApplicationServices Membership (the standard way suing MS Sql 2008 db).
My folder structure is
CONTROLLERS -- PageAController.cs -- ADMIN -- PageBController.cs
I have a Users some with Role "AdminRole", some with no rules associated (anonymouse).
I would like DENY access to the specific Controller and show a LOGIN page for
PageAController.cs
and to all Controllers within folderADMIN
for User that HAVE NOT the "AdminRole" associated.
- What it the way to go?
- Do I need setup Web.Config... how?
解决方案Hope this helps
You cannot use routing or web.config files to secure your MVC application. The only supported way to secure your MVC application is to apply the [Authorize] attribute to each controller and action method (except for the login/register methods). Making security decisions based on the current area is a Very Bad Thing and will open your application to vulnerabilities
[Authorize(Roles="AdminRole")] public class PageAController { } [Authorize(Roles="AdminRole,AnotherRole")] public class PageBController { }
这篇关于如何限制访问控制器或MVC文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!