asp.net Identity 设置自定义登录
添加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 设置自定义登录的更多相关文章
- ASP.NET Identity 简介
翻译自:http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity ,略有改动. 背景:A ...
- ASP.NET Identity 系列笔记目录
编写目的 混迹博客园已经有一段时间了,一直都是在学习各路大神的文章,自己却没有做出什么贡献,所以觉得应该写一点点内容和大家一起分享.但是本人实在才疏学浅,有心无力啊!正好最近在学习 Microsoft ...
- FineReport中如何自定义登录界面
在登录平台时,不希望使用FR默认的内置登录界面,想通过自定义登录界面实现登录操作,内置登录界面如下图: 登录界面,获取到用户名和密码的值,发送到报表系统,报表服务带着这两个参数访问认证地址进行认证. ...
- MVC5 - ASP.NET Identity登录原理 - Claims-based认证和OWIN
在Membership系列的最后一篇引入了ASP.NET Identity,看到大家对它还是挺感兴趣的,于是来一篇详解登录原理的文章.本文会涉及到Claims-based(基于声明)的认证,我们会详细 ...
- [转]MVC5 - ASP.NET Identity登录原理 - Claims-based认证和OWIN
本文转自:http://www.cnblogs.com/jesse2013/p/aspnet-identity-claims-based-authentication-and-owin.html 在M ...
- MVC5 - ASP.NET Identity登录原理 - Claims-based认证和OWIN -摘自网络
在Membership系列的最后一篇引入了ASP.NET Identity,看到大家对它还是挺感兴趣的,于是来一篇详解登录原理的文章.本文会涉及到Claims-based(基于声明)的认证,我们会详细 ...
- (转)ASP.NET Identity登录原理 - Claims-based认证和OWIN
在Membership系列的最后一篇引入了ASP.NET Identity,看到大家对它还是挺感兴趣的,于是来一篇详解登录原理的文章.本文会涉及到Claims-based(基于声明)的认证,我们会详 ...
- ASP.NET Identity登录原理 - Claims-based认证和OWIN
MVC5 - ASP.NET Identity登录原理 - Claims-based认证和OWIN 在Membership系列的最后一篇引入了ASP.NET Identity,看到大家对它还是挺感兴趣 ...
- ASP.NET Identity登录原理
https://www.cnblogs.com/jesse2013/p/aspnet-identity-claims-based-authentication-and-owin.html 如何实现登录 ...
随机推荐
- unity操作Hierarchy视图下同名的对象
上周遇到了一个令我尴尬的问题,在同一个场景内有了两个名字相同的对象,给个形象化的栗子: 场景内有橱窗,橱窗是模型,窗户是可以打开的[点击控制],窗户可以控制打开和关闭的.然后我就选用了一个保守的方式进 ...
- @property使用
# coding:utf-8 """ property:负责把方法变成属性 """ class Student(object): def g ...
- 归一化(softmax)、信息熵、交叉熵
机器学习中经常遇到这几个概念,用大白话解释一下: 一.归一化 把几个数量级不同的数据,放在一起比较(或者画在一个数轴上),比如:一条河的长度几千甚至上万km,与一个人的高度1.7m,放在一起,人的高度 ...
- firedac数据集数据序列为JSON
firedac数据集数据序列为JSON FIREDAC数据库引擎充分地考虑了跨平台和跨语言的支持. 因此,FIREDAC数据集可以序列为BIN\XML\JSON,三种格式. firedac数据集数据序 ...
- Android防止进程被第三方软件杀死
http://blog.csdn.net/wangliang198901/article/details/12342845 http://stackoverflow.com/questions/385 ...
- Android 创建单独的服务运行在后台(无界面)
转自:https://blog.csdn.net/a704225995/article/details/56481934 今天项目有个需求是,开启一个服务单独运行在后台,而且还不能有界面,在度娘搜索了 ...
- Spark2.3(三十六):根据appName验证某个app是否在运行
具体脚本 #/bin/sh #LANG=zh_CN.utf8 #export LANG export SPARK_KAFKA_VERSION=0.10 export LANG=zh_CN.UTF- # ...
- VMware: Non-VI workload detected on the datastore
check ref: Unmanaged I/O workload detected on shared datastore running Storage I/O Control (SIOC) fo ...
- Oracle只读用户角色的建立
授予某模式下对象读权限给角色,就可以建立Oracle只读用户角色,下文对该方法的实现步骤作了详细的介绍,供您参考学习. 下面为您介绍的是Oracle只读用户角色的建立方法,该方法供您参考,如果您在Or ...
- Java并发编程系列之三十二:丢失的信号
这里的丢失的信号是指线程必须等待一个已经为真的条件,在開始等待之前没有检查等待条件.这样的场景事实上挺好理解,假设一边烧水,一边看电视,那么在水烧开的时候.由于太投入而没有注意到水被烧开. 丢失的信号 ...