Mvc Identity登陆

添加引用

 

 

 添加OwinStartup类

[assembly: OwinStartup(typeof(ZLManage.App_Start.Startup))]

namespace Manage.App_Start
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // 有关如何配置应用程序的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkID=316888
            // 使应用程序可以使用 Cookie 来存储已登录用户的信息
            // 并使用 Cookie 来临时存储有关使用第三方登录提供程序登录的用户的信息
            // 配置登录 Cookie
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Home/Login"),
            });

        }
    }
}

登陆关键代码

 var identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie);
                identity.AddClaim(new Claim(ClaimTypes.Name, member.LoginName));
                //AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                AuthenticationManager.SignIn(new
                    AuthenticationProperties
                { IsPersistent = true }, identity);

 

posted @ 2020-10-18 18:04  _York  阅读(157)  评论(0编辑  收藏  举报