标签:http io ar art cti log new res
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 验证,布布扣,bubuko.com
标签:http io ar art cti log new res
原文地址:http://www.cnblogs.com/zbw911/p/3909514.html