.NET Core 2.0 Cookie中间件 权限验证
1:在ConfigureServices添加Cookie中间件,使用自定义Scheme
services.AddAuthentication(options=> {
options.DefaultChallengeScheme =“test”;
options.DefaultSignInScheme = "test";
options.DefaultAuthenticateScheme = "test";
})
.AddCookie("test", m =>
{
m.LoginPath = new PathString("/Account/Login");
m.AccessDeniedPath = new PathString("/Account/Denied");
m.LogoutPath = new PathString("/Account/Logout");
m.Cookie.Path = "/";
});
2:在Configure使用Cookie中间件 app.UseAuthentication();
、引入命名空间 using Microsoft.AspNetCore.Authentication;
4、使用方式
//登录
await HttpContext.SignInAsync("test", userPrincipal,
new AuthenticationProperties
{
ExpiresUtc = DateTime.UtcNow.AddHours(),
IsPersistent = true,
AllowRefresh = false
}); //退出
await HttpContext.SignOutAsync("test");
5、AuthorizeAsync现在返回结果为AuthorizationResult
使用方式
var result = await HttpContext.AuthenticateAsync("xxxx");
if (result.Succeeded)
{
......
}
.NET Core 2.0 Cookie中间件 权限验证的更多相关文章
- 在ASP.NET Core 中使用Cookie中间件
在ASP.NET Core 中使用Cookie中间件 ASP.NET Core 提供了Cookie中间件来序列化用户主题到一个加密的Cookie中并且在后来的请求中校验这个Cookie,再现用户并且分 ...
- net core体系-web应用程序-4net core2.0大白话带你入门-11asp.net core 2.0 cookie的使用
asp.net core 2.0 cookie的使用 本文假设读者已经了解cookie的概念和作用,并且在传统的.net framework平台上使用过. cookie的使用方法和之前的相比也有所 ...
- 在ASP.NET Core 中使用Cookie中间件 (.net core 1.x适用)
在ASP.NET Core 中使用Cookie中间件 ASP.NET Core 提供了Cookie中间件来序列化用户主题到一个加密的Cookie中并且在后来的请求中校验这个Cookie,再现用户并且分 ...
- ASP.Net Core 2.1+ Cookie 登录授权验证【简单Cookie验证】
介绍 本文章发布于博客园:https://www.cnblogs.com/fallstar/p/11310749.html 作者:fallstar 本文章适用于:ASP.NET Core 2.1 + ...
- Asp.net Core, 基于 claims 实现权限验证 - 引导篇
什么是Claims? 这个直接阅读其他大神些的文章吧,解释得更好. 相关文章阅读: http://www.cnblogs.com/JustRun1983/p/4708176.html http://w ...
- asp.net core 2.0 cookie的使用
本文假设读者已经了解cookie的概念和作用,并且在传统的.net framework平台上使用过. cookie的使用方法和之前的相比也有所变化.之前是通过cookie的add.set.clear. ...
- ASP.NET Core 2.0 Cookie Authentication
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Builder; using Microso ...
- OpenID Connect Core 1.0(三)验证
OpenID Connect执行终端用户登录或确定终端用户已经登录的验证工作.OpenID Connect 使服务器以一种安全的方式返回验证结果.所以客户可以依靠它.出于这个原因,在这种情况下客户被称 ...
- Asp.Net Core 2.0 项目实战(10) 基于cookie登录授权认证并实现前台会员、后台管理员同时登录
1.登录的实现 登录功能实现起来有哪些常用的方式,大家首先想到的肯定是cookie或session或cookie+session,当然还有其他模式,今天主要探讨一下在Asp.net core 2.0下 ...
随机推荐
- maven 配置篇 之pom.xml
http://www.blogjava.net/zyl/archive/2006/12/30/91055.html http://maven.apache.org/pom.html的翻译. m ...
- linux 文件系统与磁盘修复
fsck修复受损的文件系统 Linux不正常关机,有时候再次启动时会报文件系统损坏,如何修复文件? 首先会让你输入root用户的密码. 1)出错的时候如果告诉你是哪一块硬盘的分区有问题,比如是/ ...
- 让你的ASP.NET虚拟主机也支持子网站
现在asp.net虚拟主机一般都可以绑定多个域名,但是通过这几个域名打开的页面都一样.如何使绑的这几个域名分别打开不通的页面(即实现子网站的功能)呢? 其实很简单,只需4个步骤: 1)给虚拟主机 ...
- SLF4J warning or error messages and their meanings
来自:http://www.slf4j.org/codes.html#StaticLoggerBinder The method o.a.commons.logging.impl.SLF4FLogFa ...
- 算法笔记_230:运动员分组(Java)
目录 1 问题描述 2 解决方案 1 问题描述 有N个人参加100米短跑比赛.跑道为8条.程序的任务是按照尽量使每组的人数相差最少的原则分组.例如:N=8时,分成1组即可.N=9时,分成2组:一组 ...
- minimum-path-sum-动态规划
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...
- PCI(Payment Card Industry)合规
PCI-DSS(Payment Card Industry-Data Security Standard) 1.构建并维护安全的网络 2.保护持卡人数据 3.维护漏洞管理程序 4.执行严格的访问控制 ...
- Android开发之底部导航栏标准
以下是封装的库源码: package com.example.oldtab; import java.util.ArrayList; import android.content.res.Resour ...
- 9273:PKU2506Tiling
9273:PKU2506Tiling 来源:http://noi.openjudge.cn/ch0202/9273/ 总时间限制:2000ms 单个测试点时间限制:1000ms内存限制:131072 ...
- Jenkins中集成jmeter-maven插件
转自:http://my.oschina.net/u/1377774/blog/168969 目录[-] 第一步.先在maven工程中单独使用jmeter-maven插件 0.环境 1.在POM.xm ...