添加Startup.Auth.cs###

    public partial class Startup
{
// For more information on configuring authentication, please visit https://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
ExpireTimeSpan = TimeSpan.FromDays(3)
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); // Enables the application to remember the second login verification factor such as phone or email.
// Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
// This is similar to the RememberMe option when you log in.
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
}
}

添加Startup.cs###

注意要添加[assembly: OwinStartup(typeof(Startup))]

[assembly: OwinStartup(typeof(Startup))]
namespace testOwin
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}

在代码中就可以自己设置登录状态了###

    private ClaimsIdentity ClaimsIdentity(string userName)
{
//string[] userRoles = (string[])Session["UserRoles"]; ClaimsIdentity identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userName)); //userRoles.ToList().ForEach((role) => identity.AddClaim(new Claim(ClaimTypes.Role, role))); identity.AddClaim(new Claim(ClaimTypes.Name, userName)); //AuthenticationManager.SignIn(identity);
AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = true }, identity);
return identity;
} private IAuthenticationManager AuthenticationManager
{
get
{
return HttpContext.GetOwinContext().Authentication;
}
}

asp.net Identity 设置自定义登录的更多相关文章

  1. ASP.NET Identity 简介

    翻译自:http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity ,略有改动. 背景:A ...

  2. ASP.NET Identity 系列笔记目录

    编写目的 混迹博客园已经有一段时间了,一直都是在学习各路大神的文章,自己却没有做出什么贡献,所以觉得应该写一点点内容和大家一起分享.但是本人实在才疏学浅,有心无力啊!正好最近在学习 Microsoft ...

  3. FineReport中如何自定义登录界面

    在登录平台时,不希望使用FR默认的内置登录界面,想通过自定义登录界面实现登录操作,内置登录界面如下图: 登录界面,获取到用户名和密码的值,发送到报表系统,报表服务带着这两个参数访问认证地址进行认证. ...

  4. MVC5 - ASP.NET Identity登录原理 - Claims-based认证和OWIN

    在Membership系列的最后一篇引入了ASP.NET Identity,看到大家对它还是挺感兴趣的,于是来一篇详解登录原理的文章.本文会涉及到Claims-based(基于声明)的认证,我们会详细 ...

  5. [转]MVC5 - ASP.NET Identity登录原理 - Claims-based认证和OWIN

    本文转自:http://www.cnblogs.com/jesse2013/p/aspnet-identity-claims-based-authentication-and-owin.html 在M ...

  6. MVC5 - ASP.NET Identity登录原理 - Claims-based认证和OWIN -摘自网络

    在Membership系列的最后一篇引入了ASP.NET Identity,看到大家对它还是挺感兴趣的,于是来一篇详解登录原理的文章.本文会涉及到Claims-based(基于声明)的认证,我们会详细 ...

  7. (转)ASP.NET Identity登录原理 - Claims-based认证和OWIN

    在Membership系列的最后一篇引入了ASP.NET  Identity,看到大家对它还是挺感兴趣的,于是来一篇详解登录原理的文章.本文会涉及到Claims-based(基于声明)的认证,我们会详 ...

  8. ASP.NET Identity登录原理 - Claims-based认证和OWIN

    MVC5 - ASP.NET Identity登录原理 - Claims-based认证和OWIN 在Membership系列的最后一篇引入了ASP.NET Identity,看到大家对它还是挺感兴趣 ...

  9. ASP.NET Identity登录原理

    https://www.cnblogs.com/jesse2013/p/aspnet-identity-claims-based-authentication-and-owin.html 如何实现登录 ...

随机推荐

  1. node模块包装为Promise书写法

    1. const Promise = require('bluebird') const fs = Promise.promisifyAll(Promise.promisify(require('fs ...

  2. BZOJ2366 : 多重历史

    建立AC自动机,因为不存在某个串是另一个串的后缀,因此匹配到任意位置都只可能匹配一个串. 预处理出每个串出现的所有位置,总的出现次数为$O(m)$. 设$f[i][j]$表示考虑了前$i$个串,最后一 ...

  3. 20172302 《Java软件结构与数据结构》第三周学习总结

    2018年学习总结博客总目录:第一周 第二周 第三周 教材学习内容总结 第五章 队列 1.队列是一种线性集合,其元素从一端加入,从另一端删除:队列元素是按先进先出(FIFO(First in Firs ...

  4. maven遇到的一些问题

    (1)在加载的时候pom.xml文件是和src同级的,当在pom.xml导入jar包时一定要先把jar包所在的项目mvn install否则会报找不到的错误 (2)怎么找到maven原有的仓库? 找到 ...

  5. 学习shader之前必须知道的东西之计算机图形学-渲染管线

    引言 shader到底是干什么用的?shader的工作原理是什么? 其实当我们对这个问题还很懵懂的时候,就已经开始急不可耐的要四处搜寻有关shader的资料,恨不得立刻上手写一个出来.但看了一些资料甚 ...

  6. PKCS 15 个标准

    PKCS 全称是 Public-Key Cryptography Standards ,是由 RSA 实验室与其它安全系统开发商为促进公钥密码的发展而制订的一系列标准. 可以到官网上看看 What i ...

  7. A very simple C++ module to encrypt/decrypt strings based on B64 and Vigenere ciper.

    A very simple C++ module to encrypt/decrypt strings based on B64 and Vigenere ciper. https://github. ...

  8. angularjs 动态表单, 原生事件中调用angular方法

    1. 原生事件中调用angular方法, 比如 input的onChange事件想调用angular里面定义的方法 - onChange="angular.element(this).sco ...

  9. 基于Python3.6使用Django框架连接mysql数据库的驱动模块安装解决办法

    解决办法1 使用PyMySQL模块,直接使用pip install pymysql即可. 参考文章:https://www.cnblogs.com/wcwnina/p/8719482.html 原文内 ...

  10. python实现模拟登录

    本文主要用python实现了对网站的模拟登录.通过自己构造post数据来用Python实现登录过程.   当你要模拟登录一个网站时,首先要搞清楚网站的登录处理细节(发了什么样的数据,给谁发等...). ...