asp.net-core-identity

Inject ApplicationUser in ASP.NET Core MVC

◇◆丶佛笑我妖孽 提交于 2020-12-08 07:29:24
问题 I have a class that requires ApplicationUser (from ASP.NET Identity). The instance should be the current user. public class SomeClass { public SomeClass(ApplicationUser user) { Currently, what I'm doing is I inject the current user from the Controller: var currentUser = await _userManager.GetUserAsync(User); var instance = new SomeClass(currentUser); Now I want to use Dependency Injection provided by Microsoft. I can't figure out how am I going to add ApplicationUser to the services. It

Why doesn't cookie ExpireTimeSpan setting work?

十年热恋 提交于 2020-12-06 07:00:09
问题 I used: services.AddAuthenticationCore().ConfigureApplicationCookie(o => { o.ExpireTimeSpan = TimeSpan.FromHours(1); o.SlidingExpiration = true; }); to set my authentication cookie ExpireTimeSpan in Startup.cs in ASP.NET Core MVC project. I can see that the cookie expire-time has been set correctly in the web browser after login, but it auto logout after 30 minutes every time, even if I refresh the website every 10 seconds. If I set the ExpireTimeSpan less than 30 minutes, it can timeout