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. WebService 学习

    WebService是一种跨编程语言和跨操作系统平台的远程调用技术. XML+XSD, SOAP 和 WSDL 是构成WebService平台的三大技术. SOAP = HTTP协议 + XML数据格 ...

  2. IEnumerable和IEnumerator

    概述 IEnumerable和IEnumerator接口存在的意义:用来实现迭代的功能! public interface IEnumerable { IEnumerator GetEnumerato ...

  3. 修改easyui中datagrid表头和数据不能分开对齐的BUG。

    easyui的datagrid中表头和列只能同时全部向左对齐,全部向右对齐或者居中对齐. 有时候有需求,数据向左或向右,表头居中对齐. 在不修改源码的情况下.下面的代码可以实现该功能. 把下面代码放在 ...

  4. DNS分别在什么情况下使用UDP和TCP

    DNS同时占用UDP和TCP端口53是公认的,这种单个应用协议同时使用两种传输协议的情况在TCP/IP栈也算是个另类.但很少有人知道DNS分别在什么情况下使用这两种协议.     如果用wiresha ...

  5. ZeroClipboard 插件实现文本复制到剪贴板

    ZeroClipboard 的官网 点这里,github地址 点这里. 事例如下: 在引入 ZeroClipboard.js 之后, <button id="clip_button&q ...

  6. python RabbitMQ队列/redis

    RabbitMQ队列 rabbitMQ是消息队列:想想之前的我们学过队列queue:threading queue(线程queue,多个线程之间进行数据交互).进程queue(父进程与子进程进行交互或 ...

  7. Windows便笺 快捷键

    便笺快捷键 便笺快捷键多数与Office相同 Ctrl+N 新建 Alt+F4 关闭便笺,下次打开内容还在 Ctrl+D 删除 Ctrl+E 居中 Ctrl+R 右对齐 Ctrl+L 左对齐 Ctrl ...

  8. REST实战:SeverClient项目+RESTful理论

    理解一个新的技术,无疑就是使用它了,下面我们就通过一个可执行的demo来展现REST的原理和使用. 一 Demo 1.1 服务器端 1 主程序MainServer.java负责启动一个REST服务组件 ...

  9. Objective-C语言继承性

    • 继承性是面向对象的重要概念之一,子类能够继承父类的某些方法和成员变量.作用域限定符为private 的成员变量是不可以被继承的.子还可以重写父类的方法. • 继承是单继承,要多继承引入了协议 •子 ...

  10. win8win10以管理员身份运行cmd方法

    win8win10以管理员身份运行cmd方法 Win7/8下提示OpenSCManager failed 拒绝访问Maven nexus 安装nexus : wrapper | OpenSCManag ...