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);
OWIN is an interface between . NET web applications and web server. The main goal of the OWIN interface is to decouple the server and the applications. It acts as middleware. ASP.NET MVC, ASP.NET applications using middleware can interoperate with OWIN-based applications, servers, and middleware.
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
Note that you will need to wrap this in an async
method, such as:
@using System.Threading.Tasks;
public async Task<ActionResult> SomeMethodName(...) { //etc }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With