添加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. 实操重写IK分词器源码,基于mysql热更新词库

    实操重写IK分词器源码,基于mysql热更新词库参考网址:https://blog.csdn.net/wuzhiwei549/article/details/80451302 问题一:按照这篇文章的介 ...

  2. Object类--equals方法

    equals方法 1.比较的是对象引用的是否指向同一块内存地址 public static void main(String[] args) { HuaWei huawei=new HuaWei(); ...

  3. [Axure RP] – 鼠标滑入按钮时自动下拉表单的设计示例

    转:http://blog.qdac.cc/?p=2197 Axure RP 是个好东东呀,大大方便了程序员与客户之间的前期调研时的交流.不过有一些控制并没有鼠标移入和移出的操作,比如 HTML 按钮 ...

  4. java获取文件列表,并按照目录的深度及文件名的拼音的升序排列

    java实现在线浏览zip文件及文件下载 首先用java读出目录或是zip下的所有文件 1KG_20140718_HD/Readme-说明.htm:3.00KB1KG_20140718_HD/一键GH ...

  5. windows Server 2008 R2 添加新用户时密码不满足密码策略的要求

    ---------------------------本地用户和组---------------------------在计算机 WINSERVER2008R2 上创建用户 lintx 时,出现了以下 ...

  6. 深入学习 FutureTask

    原文出处: 天凉好个秋 第一部分:What 在Java中一般通过继承Thread类或者实现Runnable接口这两种方式来创建多线程,但是这两种方式都有个缺陷,就是不能在执行完成后获取执行的结果,因此 ...

  7. .ipynb文件转.py文件

    到要转的demo.ipynb所在目录下,然后输入命令: jupyter nbconvert --to script demo.ipynb

  8. ELK菜鸟手记 (一) 环境配置+log4j日志记录

    1. 背景介绍 在大数据时代,日志记录和管理变得尤为重要. 以往的文件记录日志的形式,既查询起来又不方便,又造成日志在服务器上分散存储,管理起来相当麻烦, 想根据一个关键字查询日志中某个关键信息相当困 ...

  9. 查看最新的Google地址

    nslookup www.google.com 8.8.8.8

  10. [AaronYang]那天有个小孩跟我说Js-NodeJS[AY0]-EJS

    按照自己的思路学习Node.Js 随心出发.EJS是Node.js中express框架中使用的一个模版引擎,当然还有Jade 我的学习就靠网上查资料,没有买书系统学,自己整理,如果有用了哪位大神的代码 ...