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取到手 新浪获取传送门 ...
随机推荐
- JS之访问器
1.在对象中定义get,set访问器属性 <script> var test = { _name:"pmx", _age:18, _born:1990, get nam ...
- easyui datagrid标题列宽度自适应
最近项目中使用easyui做前端界面,相信大部分使用过easyui datagrid的朋友有这么一个疑问:如果在columns中不设置width属性能不能写个方法让datagrid的头部标题和数据主体 ...
- 面向对象php基本格式、构造、析构、访问修饰符
<?php//面向对象//1.类//由众多的对象抽象出来的 //2.对象//一切皆对象//由类实例化出来的 //基本形式class 类名{ 成员变量 成员方法 } $对象名 =new 类名 $对 ...
- transform原点
Safari 4 Firefox3.5 Opera10.5 Chrome Internet Explorer 目前这两个属性得到了除去ie以外各个主流浏览器webkit,firefox,opera的支 ...
- 【001:ubuntu下搭建ESP8266开发环境--编辑 编译 下载】
系统环境:ubuntu 16.04 TLS 64BIT 编辑器: Eclipse CDT 版本 编译器:xtensa-lx106-elf 交叉编译工具链 下载工具:esptool.py pyseria ...
- 机器学习:异常检测算法Seasonal Hybrid ESD及R语言实现
Twritters的异常检测算法(Anomaly Detection)做的比较好,Seasonal Hybrid ESD算法是先用STL把序列分解,考察残差项.假定这一项符合正态分布,然后就可以用Ge ...
- Java:String和Date、Timestamp之间的转
Java:String和Date.Timestamp之间的转 一.String与Date(java.util.Date)互转 1.1 String -> Date String dateStr ...
- [转] 停止支持的老版本ubuntu源列表-old-releases
我使用的是ubuntu 9.10,在网上找了大半个月之后,今天终于找到了可用的源地址.感谢这位cgjcgs仁兄. 点击阅读原文 ubuntu的普通版本支持的时间都有限,过了支持的时间,更新源都会被停用 ...
- char类型的字节数
java为:两个字节,C语言中为:1个字节
- 【转】mysql安装图解
转载地址:http://www.jb51.net/article/23876.htm 很多朋友刚开始接触mysql数据库服务器,下面是网友整理的一篇mysql的安装教程,步骤明细也有详细的说明. ...