Dmitrij Polyanin Dmitrij Polyanin - 3 months ago 23
C# Question

How to check is the current session is persistent or not?

When i am doing user LogOn i need to set IsPersistent parameter

SignInManager.SignIn(user, isPersistent, false);


On my site i have functionality of changing UserName of current user. If UserName has changed my current coockies make not actual, so i need to LogOut user and then to login, but i dont know is user checked remmember me or not.
How can i in my site know is session isPersistent or not?
Or is there any other way to handle changing UserName not desinchron with coockies?

UPDATE:

I use

_user = db.Users.FirstOrDefault(x => x.UserName == User.Identity.Name);


in my Base Controller to track current User.
Asp.Net Identity has property
User.Identity.Name
but not
User.Identity.Id
, and this name stored somewhere in coockies. Is there any way to change system to track not names but ids?

Answer

Did you tried below

Thread.CurrentPrincipal.Identity.GetUserId()