public static void Authentication(this HttpContextBase httpcontext, ManageUser manageuser)
        {
            ClaimsIdentity _identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie);
            _identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, manageuser.UserID.ToString()));
            _identity.AddClaim(new Claim(ClaimTypes.Name, manageuser.UserName));
            _identity.AddClaim(new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity"));

            httpcontext.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
            httpcontext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties() { IsPersistent = true }, _identity);
        }
Esempio n. 2
0
 public ActionResult Index(ManageUser mu)
 {
     ManageUser mu1 = new BLLManageUser().GetByUserName(mu.UserName);
     if (mu1 == null)
     {
         ViewBag.ErrorMsg = "不存在的用户名!";
         return View(new ManageUser());
     }
     if (mu1.Pwd != mu.Pwd)
     {
         ViewBag.ErrorMsg = "密码错误";
         mu.Pwd = "";
         return View(mu);
     }
     UserAuthentication.Authentication(Request.RequestContext.HttpContext, mu);
     return Redirect("/Main/Index");
 }