zoukankan      html  css  js  c++  java
  • 自定义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);
            }
        }
  • 相关阅读:
    虚拟机三种虚拟网络的区别
    关于 三次握手和四次挥手 的生动解析
    Tkinter布局管理器
    F#周报2019年第4期
    F#周报2019年第3期
    ML.NET 0.9特性简介
    F#周报2019年第2期
    浏览器保存数据的几种方法
    F#周报2019年第1期
    ML.NET教程之客户细分(聚类问题)
  • 原文地址:https://www.cnblogs.com/zbw911/p/3909514.html
Copyright © 2011-2022 走看看