Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read MVC OWIN AuthenticationProperties?

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);
like image 491
nik Avatar asked Jul 23 '14 00:07

nik


People also ask

What is Owin MVC?

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.


1 Answers

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 }
like image 75
Alfred Wallace Avatar answered Oct 11 '22 11:10

Alfred Wallace