添加引用

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);

 

相关文章:

  • 2022-12-23
  • 2021-06-08
  • 2021-05-26
  • 2021-11-24
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
猜你喜欢
  • 2022-12-23
  • 2022-01-20
  • 2022-01-09
  • 2021-08-29
  • 2022-12-23
相关资源
相似解决方案