zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    java笔记
    java面向对象
    Oracle数据库基础
    Java中的集合和常用类
    Java面向对象的三个特征
    Java中的类与对象
    Java中的冒泡排序
    JAVA中的一些内置方法
    JAVA中的数据类型
    SSH整合
  • 原文地址:https://www.cnblogs.com/tangchun/p/13836375.html
Copyright © 2011-2022 走看看