ASP.Net Kernel ID Canceled by Using FindByIdAsync

I have a small project that uses the Asp.Net Core Identity framework along with EF Core. One function calls UserManager.FindByIdAsync (id) and returns the corresponding object. However, it only works a few minutes after starting the application. While the server is busy, it works fine, but as soon as the application is idle for more than 1-2 minutes, the request fails.

Failure:

*OperationCanceledException: The operation was canceled.
System.Threading.CancellationToken.ThrowOperationCanceledException()*

The stacktrace element is as follows:

*System.Threading.CancellationToken.ThrowOperationCanceledException()
Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore.FindByIdAsync(string userId, CancellationToken cancellationToken)
Microsoft.AspNetCore.Identity.UserManager.FindByIdAsync(string userId)
MyProject.Areas.Admin.ControllerServices.UserService+<GetUser>d__11.MoveNext() in UserService.cs*

I am still logged in as other pages are working fine. A simple EF call context.Users.FindAsync(new object[] { id })will work as expected, but the next line containing FindByIdAsyncwill fail.

dev, , IIS WS 2008 R2. , .

, , "Connection id" 0HL5E91K33IIQ "reset." , . .

FindByIdAsync , , .

?

+4
2

, , , - .

. UserManager IHttpContextAccessor ( CancellationToken), , . IHttpContextAccessor Singleton, UserManager . , UserManager, ​​ Singleton. Scoped .

+5

, "" ASP.Net Core DI. SimpleInjector, ASP.Net Identity Core , , . - SimpleInjector, , " " "". AccountController framework . app.ApplicationServices.GetService<AccountController>() , Singleton, ! , , SimpleInjector . , ( ), . SimpleInjectors, app.GetRequiredRequestService<AccountController>().

asp.net core 2.0

fishy singleton, : System.InvalidOperationException: 'Cannot resolve scoped service 'WebApplication15.Controllers.AccountController' from root provider.'

0

Source: https://habr.com/ru/post/1678766/


All Articles