asp.net – 如何在MVC 5中为OwinContext设置TimeOut
发布时间:2020-12-15 23:15:00 所属栏目:asp.Net 来源:网络整理
导读:当用户访问网站并输入存储在我们的数据库中的凭据时,我们在创建身份验证时. 你如何设置超时? 使用MVC 5. 我的身份验证如下所示: var claims = new ListClaim(); claims.Add(new Claim("UserId",user.UserID.ToString())); claims.Add(new Claim(ClaimTypes
当用户访问网站并输入存储在我们的数据库中的凭据时,我们在创建身份验证时.
你如何设置超时? 我的身份验证如下所示: var claims = new List<Claim>(); claims.Add(new Claim("UserId",user.UserID.ToString())); claims.Add(new Claim(ClaimTypes.Name,user.FirstName + " " + user.LastName)); claims.Add(new Claim(ClaimTypes.Email,user.Email)); claims.Add(new Claim(ClaimTypes.NameIdentifier,user.UserID.ToString())); var id = new ClaimsIdentity(claims,DefaultAuthenticationTypes.ApplicationCookie); var ctx = Request.GetOwinContext(); var authenticationManager = ctx.Authentication; authenticationManager.SignIn(id); 解决方法
设置固定的到期时间跨度的方法是在Startup.Auth.cs文件中设置ExpireTimeSpan属性,如下所示:
// Enable the application to use a cookie to store information for the signed in user app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,LoginPath = new PathString("/Account/Login"),ExpireTimeSpan = TimeSpan.FromDays(2) }); 请注意,您还必须将cookie设置为持久.在您的代码中,除了用户名和密码之外,还必须传入bool,然后更改 authenticationManager.SignIn(id); 成为 authenticationManager.SignIn(new AuthenticationProperties { IsPersistent = rememberMe },id); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – @ Html.EditorForModel()下拉列表
- Phonegap上的ASP.NET窗体身份验证问题(Android)
- asp.net – 解决大型RewriteMap配置部分
- 详解ASP.NET配置文件Web.config
- asp.net-mvc – 在ASP.NET MVC中上传多个图像文本字段
- asp.net-mvc – 使用Url.action调用控制器方法时,只有第一个
- 在ASP.NET MVC中为复杂数据验证放置数据管理规则的位置?
- asp.net – MVC2 – 逻辑应该去的基本问题
- asp.net-mvc – 用于服务应用程序的Microsoft Graph API au
- asp.net – ASP.MVC CORE网站的最大上传大小
推荐文章
站长推荐
- asp.net – 可以创建.config文件并将其包含到web
- asp.net-mvc – MVC3在编辑时,十进制截断为2位小
- asp.net – 适用于.NET开发人员的Windows 7版本
- asp.net – 休闲网站的密码规则
- 如何计算列的总和并在Asp.net的Jqgrid中显示在Fo
- ASP.NET MVC3角色和权限管理 – >具有运行时权限
- 本地化 – 了解MVC6 RC1中的资源文件
- asp.net-mvc – MVC2中的REQUIRED String属性的服
- asp.net – Azure中的IP安全性和始终开启设置
- asp.net-mvc – HttpContext.Current.User.IsInR
热点阅读