ASP.NET MVC 3 - 如何限制以高效的方式方面呢? [英] ASP.NET MVC 3 - How to restrict areas in an efficient way?

查看:102
本文介绍了ASP.NET MVC 3 - 如何限制以高效的方式方面呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC 3站点管理面板(我们不都是:) - ?我用我自己的解决方案非常安全登录系统

I've got an ASP.NET MVC 3 site with an admin panel (don't we all? :) - I've used my own solution for a very secured login system.

现在,在管理员控制每个视图我需要检查用户登录并具有正确的授权,所以每次我单独运行在每个视图相同的验证和授权的方法。

Now, on each view in the admin controller I need to make checks that the user is logged and has the proper authorization, so each time I run the same verification and authorization methods on each view separately.

我如何才能让所有的要求有一定的控制器相同的检查? (我的意思是,对所有的检查只有一次,在一个地方)

How could I make the same checks for all the requests to a certain controller? (I mean, right all the checks only once and in one place)

(我也想有一个例外,所以我可以允许用户使用登录页它的管理控制器和外部内部)

(I also would like to have an exception, so I could allow user to use the login page inside the admin controller and outside of it)

谢谢!

推荐答案

使用控制器上的一个属性。无论是标准的 AuthorizeAttribute (见的这个),或写自己的。

Use an attribute on the controller. Either the standard AuthorizeAttribute (see this) or write your own.

这篇关于ASP.NET MVC 3 - 如何限制以高效的方式方面呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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