如何阅读MVC OWIN AuthenticationProperties? [英] How to read MVC OWIN AuthenticationProperties?
本文介绍了如何阅读MVC OWIN AuthenticationProperties?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在登录用户时正在设置IsPersistent,如何读回该值?
I'm setting IsPersistent when signing the user in, how to read that value back?
var identity = await UserManager.CreateIdentityAsync(appUser, DefaultAuthenticationTypes.ApplicationCookie);
HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties() { IsPersistent = false }, identity);
推荐答案
AspNet.Identity
使您可以访问会话的IsPersistent
的bool
值.读取其值的最直接方法是调用AuthenticateAsync()
:
AspNet.Identity
gives you access to the bool
value of IsPersistent
for the session. The most direct way to read its value is to call AuthenticateAsync()
:
@using Microsoft.AspNet.Identity;
var authenticateResult = await HttpContext.GetOwinContext()
.Authentication.AuthenticateAsync(
DefaultAuthenticationTypes.ApplicationCookie
);
var isPersistent = authenticateResult.Properties.IsPersistent; //// true or false
请注意,您需要将其包装在async
方法中,例如:
Note that you will need to wrap this in an async
method, such as:
@using System.Threading.Tasks;
public async Task<ActionResult> SomeMethodName(...) { //etc }
这篇关于如何阅读MVC OWIN AuthenticationProperties?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文