自定义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 ...
随机推荐
- UVA1476 三分法
单峰函数(即先递增后递减,有极大值的函数),都可以用三分法来求 #include <iostream> #include <cmath> #include <cstdio ...
- HDU 3357
http://acm.hdu.edu.cn/showproblem.php?pid=3357 给出公司间的控股关系,问有多少组不合法数据,自己控股自己不合法,a控股b,b控股c,则a控股c 其实就是找 ...
- I.MX6 bootargs 内核参数设定
/******************************************************************** * I.MX6 bootargs 内核参数设定 * 说明: ...
- python内置的数据结构
详解列表List 这里是列表对象方法的清单: list.append(x) 添加一个元素到列表的末尾.相当于a[len(a):] = [x]. list.extend(L) 将给定列表L中的所有元素附 ...
- 本地安装git
在ubuntu上安装git特别简单 首先用命令查看是否安装git 在终端输入 git 如果没有安装 sudo apt-get install git 安装完之后,测试是否安装成功: git --ver ...
- HDU 5748 最长上升子序列的长度nlogn(固定尾部)
Bellovin Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- ZOJ 1216 Deck
原题链接 题目大意:1/2+1/4+1/6+…1/n 解法:直接累加即可. 参考代码: #include<stdio.h> int main(){ printf("# Cards ...
- PCL可视化显示 直接加载显示pcb文件
简单可视化类,是指直接在程序中使用,而且不支持多线程. #include<iostream> #include<pcl\point_cloud.h> #include<p ...
- Codeforces Round #114 (Div. 2)
Codeforces Round #114 (Div. 2) 代码 Codeforces Round #114 (Div. 2) C. Wizards and Trolleybuses 思路 每条车的 ...
- Android——单元测试
在实际开发中,开发android软件的过程需要不断地进行测试.而使用Junit测试框架,侧是正规的Android开发的必用技术,在Junit中可以得到组件,可以模拟发送事件和检测程序处理的正确性. 第 ...