Base solution for your next web application
Open Closed

Current user did not login error when running web app through web farm #11682


User avatar
0
varunab created

Hi, I'm using ASP.Net zero MVC and JQuvery version 11.4. My production environment consists of 2 Windows Server 2019 and I have deployed the solution on IIS on each server. Running the app through the VMs individually works well, but when running through load balancer, i get error Current User did not login and I see signalR errors when I open the developers tool.

I'm trying to implement persistence to resolve the issue. I have extended my DbContext and added IDataProtectionKeyContext public class cmsDbContext : AbpZeroDbContext<Tenant, Role, User, cmsDbContext>, IAbpPersistedGrantDbContext, IDataProtectionKeyContext. and public DbSet<DataProtectionKey> DataProtectionKeys { get; set; }

I now need to add the following line of code: services.AddDataProtection().PersistKeysToDbContext<cmsDbContext>();

When adding it in ConfigureServices in Startup.cs of the MVC project, i get the following error:

ERROR 2023-08-14 13:32:10,890 [13 ] AspNetCore.Server.IIS.Core.IISHttpServer - Connection ID "18158513719837982721", Request ID "40000002-0005-fc00-b63f-84710c7967bb": An unhandled exception was thrown by the application. System.Security.Cryptography.CryptographicException: An error occurred while trying to encrypt the provided data. Refer to the inner exception for more information. For more information go to http://aka.ms/dataprotectionwarning ---> Castle.MicroKernel.Handlers.HandlerException: Can't create component 'judiciary.cms.EntityFrameworkCore.cmsDbContext' as it has dependencies to be satisfied.

'judiciary.cms.EntityFrameworkCore.cmsDbContext' is waiting for the following dependencies:

  • Service 'Microsoft.EntityFrameworkCore.DbContextOptions`1[[judiciary.cms.EntityFrameworkCore.cmsDbContext, judiciary.cms.EntityFrameworkCore, Version=11.4.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.

    at Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency() at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, Arguments additionalArguments, IReleasePolicy policy, Boolean ignoreParentContext) at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, Arguments arguments, IReleasePolicy policy, Boolean ignoreParentContext) at Castle.MicroKernel.DefaultKernel.Resolve(Type service, Arguments arguments) at Castle.Windsor.MsDependencyInjection.ScopedWindsorServiceProvider.GetServiceInternal(Type serviceType, Boolean isOptional) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.EntityFrameworkCoreXmlRepository1.&lt;GetAllElements&gt;g__GetAllElementsCore|3_0()+MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.EntityFrameworkCoreXmlRepository1.GetAllElements() at Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.GetAllKeys() at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.CreateCacheableKeyRingCore(DateTimeOffset now, IKey keyJustAdded) at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.ICacheableKeyRingProvider.GetCacheableKeyRing(DateTimeOffset now) at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRingCore(DateTime utcNow, Boolean forceRefresh) at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRing() at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(Byte[] plaintext) --- End of inner exception stack trace --- at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(Byte[] plaintext) at Microsoft.AspNetCore.Session.CookieProtection.Protect(IDataProtector protector, String data) at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context) at Abp.AspNetCore.Mvc.Caching.GetScriptsResponsePerUserCacheMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context) at Microsoft.WebTools.BrowserLink.Net.BrowserLinkMiddleware.ExecuteWithFilterAsync(IHttpSocketAdapter injectScriptSocket, String requestId, HttpContext httpContext) at Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware.InvokeAsync(HttpContext context) at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT1.ProcessRequestAsync()

Any idea on how to resolve this?

Thanks


2 Answer(s)