How to handle expired access token in asp.net core using refresh token with OpenId Connect

It seems there is no programming in the openidconnect authentication for asp.net core to manage the access_token on the server after received. I found that I can intercept the cookie validation event and check if the access token has expired. If so, make a manual HTTP call to the token endpoint with the grant_type=refresh_token. By … Read more

Error: “There was an error running the selected code generator: Package restore failed”

I also had this issue. “Add Controller>API Controller with actions, using Entity Framework” would give the “Package Restore Failed” error. As Anish stated, it seems to be due to package versions being mis-aligned. I was able to resolve this issue using “Manage NUGET Packages for Solution”, then performing an “Update All”. This set my AspNetCore … Read more

HttpContext in .net standard library

There’s a problem to your approach: .NET Standard is the most bare-bones implementation of .NET available, meaning that only basic features which are platform- and scenario-agnostic are implemented. HttpContext exists on both the .NET Framework and .NET Core (both of which implement .NET Standard, by the way), but being specific to the Web, it does … Read more

Add Response Headers to ASP.NET Core Middleware

Never mind, the code is here public async Task Invoke(HttpContext context) { var watch = new Stopwatch(); watch.Start(); //To add Headers AFTER everything you need to do this context.Response.OnStarting(state => { var httpContext = (HttpContext)state; httpContext.Response.Headers.Add(“X-Response-Time-Milliseconds”, new[] { watch.ElapsedMilliseconds.ToString() }); return Task.CompletedTask; }, context); await _next(context); }

No service for type ‘Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]’ has been registered

This usually happens in the _LoginPartial.cshtml or _ManageNav.cshtml razor view. Eg. @inject UserManager<IdentityUser> userManager Must be changed to @inject UserManager<MyUserStore> userManager The same applies to SignInManager. When registering your own MyUserStore (bad name, should be MyUser) for the AspNetCore Identity, the UserManager<> type will be registered to the ServiceCollection as UserManager<MyUserStore>. Whenever you want to … Read more