自定义Mvc5 Owin 验证
public class AuthIn : IUserAuthenticate { public static ApplicationUserManager UserManager { get { return HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>(); } } private IAuthenticationManager AuthenticationManager { get { return HttpContext.Current.GetOwinContext().Authentication; } } public void CurUserLoginOut() { AuthenticationManager.SignOut(); } public bool GetUserIsAuthenticated() { return HttpContext.Current.User.Identity.IsAuthenticated; } public void SignUserLogin(string strUserName, Dictionary<string, string> extDatas) { ApplicationUser user = UserManager.FindByName(strUserName); if (user == null) { user = new ApplicationUser { UserName = strUserName, Email = extDatas["Email"] }; IdentityResult result = Task.Factory.StartNew(s => { return ((ApplicationUserManager)s).CreateAsync(user); }, UserManager).Unwrap().GetAwaiter().GetResult(); if (!result.Succeeded) { HttpContext.Current.Response.Write("Error on Create User"); return; } } ClaimsIdentity indentiy = Task.Factory.StartNew(s => { return user.GenerateUserIdentityAsync(((ApplicationUserManager)s)); }, UserManager).Unwrap().GetAwaiter().GetResult(); AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = false }, indentiy); } }
自定义Mvc5 Owin 验证的更多相关文章
- WCF 安全性之 自定义用户名密码验证
案例下载 http://download.csdn.net/detail/woxpp/4113172 客户端调用代码 通过代理类 代理生成 参见 http://www.cnblogs.com/woxp ...
- 【WCF】Silverlight+wcf+自定义用户名密码验证
本文摘自 http://www.cnblogs.com/virusswb/archive/2010/01/26/1656543.html 在昨天的博文Silverlight3+wcf+在不使用证书的情 ...
- jquery.validate.js之自定义表单验证规则
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- Spring MVC 项目搭建 -6- spring security 使用自定义Filter实现验证扩展资源验证,使用数据库进行配置
Spring MVC 项目搭建 -6- spring security使用自定义Filter实现验证扩展url验证,使用数据库进行配置 实现的主要流程 1.创建一个Filter 继承 Abstract ...
- Spring-Security 自定义Filter完成验证码校验
Spring-Security的功能主要是由一堆Filter构成过滤器链来实现,每个Filter都会完成自己的一部分工作.我今天要做的是对UsernamePasswordAuthenticationF ...
- ASP.NET Core的JWT的实现(自定义策略形式验证).md
既然选择了远方,便只顾风雨兼程 __ HANS许 在上篇文章,我们讲了JWT在ASP.NET Core的实现,基于中间件来实现.这种方式有个缺点,就是所有的URL,要嘛需要验证,要嘛不需要验证,没有办 ...
- layui 自定义表单验证的几个实例
*注:使用本方法请先引入layui依赖的layu.js和layui.css 1.html <input type="text" name="costbudget&q ...
- 基于struts2框架-自定义身份证号验证器
自定义拦截器的步骤: 1.定义一个验证器的类: > 自定义的验证器都需要实现 Validator接口. > 可以选择继承 ValidatorSupport 或 FieldValidato ...
- Angular5+ 自定义表单验证器
Angular5+ 自定义表单验证器 Custom Validators 标签(空格分隔): Angular 首先阐述一下遇到的问题: 怎样实现"再次输入密码"的验证(两个cont ...
随机推荐
- C#操作txt问件,进行清空添加操作
//把txt清空 FileStream stream = File.Open(Adr,FileMode.OpenOrCreate,FileAccess.Write); stream.Seek(, Se ...
- Osmocom-BB中cell_log的多种使用姿势
转载留做备份,原文地址:http://92ez.com/?action=show&id=23342 翻阅osmocom-bb源码的时候注意到,在cell_log中有非常多我们从来没有注意到的功 ...
- River Crossing 简单的动态规划 .
第一行 t 表示有几组测试数据 . 每组测试数据的 第一行是 n, m . 然后 下面有n行数据 . 题意:有1个人和N只羊要过河.一个人单独过河花费的时间是M,每次带一只羊过河花费时 ...
- PHP面向对象的程序设计一些简单的概念
一.面向对象的概述 数组和对象,都属于PHP中的复合类型(一个变量可以存储多个单元) 对象比数组更强大,不仅可以存储多个数据,还可以将函数存在对象中 对象的三大特性:封装,继承,多态 面向对象编 ...
- 2013杭州现场赛B题-Rabbit Kingdom
杭州现场赛的题.BFS+DFS #include <iostream> #include<cstdio> #include<cstring> #define inf ...
- Arrays Multi
<!DOCTYPE html><html><body><?php$cars = array ( array("Volvo",22, ...
- hbm2ddl
hbm2ddl工具位于Hibernate核心软件包中,而hbm2java工具位于Hibernate工具包中,因此需要下载Hibernate工具包,文件形式为HibernateTools-X.zip. ...
- HDU 4856
http://acm.hdu.edu.cn/showproblem.php?pid=4856 西安邀请赛的一道题,这道题我们当时在现场最后1h才发现时状态压缩dp,惊险写出 现在回头想发现当时有点呆, ...
- 【转】What is an entity system framework for game development?
What is an entity system framework for game development? Posted on 19 January 2012 Last week I relea ...
- 设备、像素和点 、 9切片技术 、 颜色和外观 、 NavigationBar的美化
1 TMessage项目的输入面板界面 1.1 问题 IOS中经常会使用到九切片技术对图片进行处理.本案例使用九切片技术完成Tmessage项目的输入板界面,如图-1所示: 图-1 1.2 方案 首先 ...