Security » Authorization » 简单授权
Simple Authorization¶ 简单授权
Authorization in MVC is controlled through the AuthorizeAttribute attribute and its various parameters. At its simplest applying the AuthorizeAttribute attribute to a controller or action limits access to the controller or action to any authenticated user.
MVC中的授权通过AuthorizeAttribute属性及其不同的参数来实现。控制器或者方法的AuthorizeAttribute 属性最简单的应用是限制认证用户的使用。
For example, the following code limits access to the AccountController to any authenticated user.
例如,下列代码限制只有授权用户才能连接AccountController 。
[Authorize]
public class AccountController : Controller
{
public ActionResult Login()
{
} public ActionResult Logout()
{
}
}
If you want to apply authorization to an action rather than the controller simply apply the AuthorizeAttribute attribute to the action itself;
如果想对一个方法实施授权,而不是简单地对控制器实施授权,那么仅将AuthorizeAttribute 属性放到该方法上。
public class AccountController : Controller
{
public ActionResult Login()
{
} [Authorize]
public ActionResult Logout()
{
}
}
Now only authenticated users can access the logout function.
现在,只有授权用户可以使用logout函数。
You can also use the AllowAnonymousAttribute attribute to allow access by non-authenticated users to individual actions; for example
你也可使用AllowAnonymousAttribute 属性来允许非授权用户使用单独的方法,例如:
[Authorize]
public class AccountController : Controller
{
[AllowAnonymous]
public ActionResult Login()
{
} public ActionResult Logout()
{
}
}
This would allow only authenticated users to the AccountController, except for the Login action, which is accessible by everyone, regardless of their authenticated or unauthenticated / anonymous status.
这会使除了Login方法外,只有授权用户可以使用AccountController,不论其授权或者非授权以及匿名的任何人都可使用Login方法。
Warning 注意
[AllowAnonymous] bypasses all authorization statements. If you apply combine [AllowAnonymous] and any [Authorize] attribute then the Authorize attributes will always be ignored. For example if you apply [AllowAnonymous] at the controller level any [Authorize] attributes on the same controller, or on any action within it will be ignored.
[AllowAnonymous] 忽略了所有的授权语句。如果联合使用 [AllowAnonymous]和[Authorize] 属性,Authorize属性将一直被忽略。例如:如果在控制器级别使用了[AllowAnonymous],在同一个控制器的任何[Authorize]或者其中的任何方法将被忽略。
Security » Authorization » 简单授权的更多相关文章
- Security » Authorization » 基于自定义策略的授权
Custom Policy-Based Authorization¶ 基于自定义策略的授权 98 of 108 people found this helpful Underneath the cov ...
- Spring Security 解析(一) —— 授权过程
Spring Security 解析(一) -- 授权过程 在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把Spring Security .S ...
- Spring Authorization Server授权服务器入门
11月8日Spring官方已经强烈建议使用Spring Authorization Server替换已经过时的Spring Security OAuth2.0,距离Spring Security OA ...
- Lind.DDD.Authorization用户授权介绍
回到目录 Lind.DDD.Authorization是Lind.DDD框架的组成部分,之所以把它封装到框架里,原因就是它的通用性,几乎在任何一个系统中,都少不了用户授权功能,用户授权对于任何一个系统 ...
- Security » Authorization » 介绍
Introduction¶ 介绍 77 of 87 people found this helpful Authorization refers to the process that determi ...
- IdentityServer4之Authorization Code(授权码)相对更安全
前言 接着授权模式聊,这次说说Authorization Code(授权码)模式,熟悉的微博接入.微信接入.QQ接入都是这种方式(这里说的是oauth2.0的授权码模式),从用户体验上来看,交互方式和 ...
- [转]OAuth 2.0 - Authorization Code授权方式详解
本文转自:http://www.cnblogs.com/highend/archive/2012/07/06/oautn2_authorization_code.html I:OAuth 2.0 开发 ...
- OAuth : open Authorization 开发授权
OAuth : open Authorization 开发授权 用户访问慕课网,慕课网请求OAuth登陆页面,用户输入QQ号码和密码,这个页面的域名不属于慕课网是属于QQ的,随后把结果给慕课网,这个结 ...
- OAuth 2.0 - Authorization Code授权方式详解
I:OAuth 2.0 开发前期准备 天上不会自然掉馅饼让你轻松地去访问到人家资源服务器里面的用户数据资源,所以你需要做的前期开发准备工作就是把AppKey, AppSecret取到手 新浪获取传送门 ...
随机推荐
- 微信sdk分享,苹果手机分享到qq好友和qq空间没有反应
最近线上程序苹果手机进行微信分享时,分享到qq好友和qq空间,无法调用分享程序,从微信跳转到qq后就没有反应了,但是安卓手机分享就没事? 解决:调用微信sdk分享时,分享的url(link)的参数不能 ...
- 20145320《Java程序设计》第9周学习总结
20145320<Java程序设计>第9周学习总结 教材学习内容总结 16.整合数据库 JDBC(java DateBase Connectivity)是用于执行SQL的解决方案,开发人员 ...
- ios -- 教你如何轻松学习Swift语法(一)
目前随着公司开发模式的变更,swift也显得越发重要,相对来说,swift语言更加简洁,严谨.但对于我来说,感觉swift细节的处理很繁琐,可能是还没适应的缘故吧.基本每写一句代码,都要对变量的数据类 ...
- C++复现经典游戏——扫雷
国庆小长假,当大家都去看人山人海的时候,我独自一人狂码代码.这两天想要实现的内容是Windows上的一个经典游戏——扫雷.相信90后和一些上班族对此并不陌生.然而,从win8开始,扫雷就不再是Wind ...
- [原创]java WEB学习笔记97:Spring学习---Spring 中的 Bean 配置:IOC 和 DI
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- 配置Hibernate二级缓存
首先找到配置EHCahe二级缓存需要添加的jar包 hibernate-release-4.1.9.Final→lib→optional→ehcache→下的ehcache-core-2.4.3.ja ...
- Unity操作
聚焦到游戏物体: Hierarchy界面选中需要聚焦的物体,双击或者使用快捷键“F”: 在Scene面板中选中物体,使用快捷键“F” 放大缩小物体: alt+鼠标右键:鼠标滑轮 从各个角度观察 ...
- Java并发编程初探
package test; import java.io.File; import java.io.FileReader; import java.io.IOException; import jav ...
- Objective-C语言分类与协议
分类(Category)允许向一个类文件中添加新的方法声明,它不需要使用子类机制,并且在类实现的文件中的同一个名字下定义这些方法.其语法举例如下: #import "ClassName.h& ...
- 普华永道高级JAVA面试记录
最近在考虑换个工作 原因?咱能不逗吗? 一面感觉发挥不错 二面之后累觉不爱 基本上浪费了半天的工资(好多钱啊~~~) PWD上海地址在浦东软件园 工作环境说实话没我现在工作的环境好,不过里面的人 ...