Simple Authorization 简单授权

82 of 86 people found this helpful

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 » 简单授权的更多相关文章

  1. Security » Authorization » 基于自定义策略的授权

    Custom Policy-Based Authorization¶ 基于自定义策略的授权 98 of 108 people found this helpful Underneath the cov ...

  2. Spring Security 解析(一) —— 授权过程

    Spring Security 解析(一) -- 授权过程   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把Spring Security .S ...

  3. Spring Authorization Server授权服务器入门

    11月8日Spring官方已经强烈建议使用Spring Authorization Server替换已经过时的Spring Security OAuth2.0,距离Spring Security OA ...

  4. Lind.DDD.Authorization用户授权介绍

    回到目录 Lind.DDD.Authorization是Lind.DDD框架的组成部分,之所以把它封装到框架里,原因就是它的通用性,几乎在任何一个系统中,都少不了用户授权功能,用户授权对于任何一个系统 ...

  5. Security » Authorization » 介绍

    Introduction¶ 介绍 77 of 87 people found this helpful Authorization refers to the process that determi ...

  6. IdentityServer4之Authorization Code(授权码)相对更安全

    前言 接着授权模式聊,这次说说Authorization Code(授权码)模式,熟悉的微博接入.微信接入.QQ接入都是这种方式(这里说的是oauth2.0的授权码模式),从用户体验上来看,交互方式和 ...

  7. [转]OAuth 2.0 - Authorization Code授权方式详解

    本文转自:http://www.cnblogs.com/highend/archive/2012/07/06/oautn2_authorization_code.html I:OAuth 2.0 开发 ...

  8. OAuth : open Authorization 开发授权

    OAuth : open Authorization 开发授权 用户访问慕课网,慕课网请求OAuth登陆页面,用户输入QQ号码和密码,这个页面的域名不属于慕课网是属于QQ的,随后把结果给慕课网,这个结 ...

  9. OAuth 2.0 - Authorization Code授权方式详解

    I:OAuth 2.0 开发前期准备 天上不会自然掉馅饼让你轻松地去访问到人家资源服务器里面的用户数据资源,所以你需要做的前期开发准备工作就是把AppKey, AppSecret取到手 新浪获取传送门 ...

随机推荐

  1. Unit04 - 继承的意义(下) 、 访问控制 、 static和final

    Unit04  -  继承的意义(下) . 访问控制 . static和final 1.方法的重写(Override):重新写.覆盖  1)发生在父子类中,方法名称相同,参数列表相同,方法体不同  2 ...

  2. 20145320《Java程序设计》第一次实验报告

    20145320<Java程序设计>第一次实验报告 北京电子科技学院(BESTI)实验报告 课程:Java程序设计 班级:1453 指导教师:娄嘉鹏 实验日期:2016.04.08 18: ...

  3. 使用 robotframework 自动化测试系列 一 -----简介

    robotframework 是自动化测试框架. Robot Framework是一款python编写的功能自动化测试框架.具备良好的可扩展性,支持关键字驱动,可以同时测试多种类型的客户端或者接口,可 ...

  4. iOS 杂记

    一,demo 1,视图跳转 MaryPopin:  https://github.com/Backelite/MaryPopin 2,Nimbus是一个开源的iOS框架,比起Three20,Nimbu ...

  5. C#中把Datatable转换为Json的5个代码实例

    一. /// <summary> /// Datatable转换为Json /// </summary> /// <param name="table" ...

  6. java中BigDecimal加减乘除基本用法

    Java在java.math包中提供的API类BigDecimal,用来对超过16位有效位的数进行精确的运算.双精度浮点型变量double可以处理16位有效数. 在实际应用中,需要对更大或者更小的数进 ...

  7. 161215、MySQL 查看表结构简单命令

    一.简单描述表结构,字段类型desc tabl_name;显示表结构,字段类型,主键,是否为空等属性,但不显示外键.二.查询表中列的注释信息select * from information_sche ...

  8. DirectUI 收集资料

    1.[ZsUI]一步一步写个DirectUI.[连载贴] (http://tieba.baidu.com/p/1625954225) ps: 虽然是vb写的,也很简陋,不过有代码,并且作者每节都给出了 ...

  9. popUpWindow 动画无法超出窗体的解决方案

    popupWindow 做动画时,当要求有一个放大动画时,动画无法超出窗体,给人的感觉是只有内容在放大,窗体不动. 这是由于窗口大小固定的原因,解决方案是加大popUpwindow的 大小. 一个比较 ...

  10. Java 菜鸟学习之 script脚本语句

    脚本语句  一般分为  顺序语句   分支语句   循环语句 顺序语句  就是从上到下依次读取 分支语句 是if语句 if(判断条件) { 满足条件执行的语句 } else { 不满足条件执行的语句 ...