Giter VIP home page Giter VIP logo

Comments (6)

JonPSmith avatar JonPSmith commented on July 20, 2024 1

I am pretty sure that your shardingsettings.Production.json file doesn't have the correct data in it.

One of the changes I made in version 5.0.1 to the ShardingConnectionsJsonFile service such that if you call the FormConnectionString and TestFormConnectionString methods and if the named DatabaseInformation isn't found you get a exception (previously it returned a null connection string which causes a problem later, and often harder to find).

So, if your shardingsettings.Production.json hasn't got a DatabaseInformation entry for a AuthP tenant, then you will get an exception. I should say that you would get an error with version 5.0.0, but it will something more subtle, like not getting tenant data or ITenantChangeService code doesn't work properly.

You can fix the mismatch by:

  • Get a list of the Tenants in the AuthP's production database and look at the DatabaseInfoName in each Tenant.
  • Then look in your shardingsettings.Production.json and check you have an entry with the Name the tenant's DatabaseInfoName.
  • Then you can manually edit the shardingsettings.Production.json to add any missing DatabaseInformations.

from authpermissions.aspnetcore.

JonPSmith avatar JonPSmith commented on July 20, 2024 1

Glad you could fix things. Notice that I have updated the issue name in case other people have these problems when upgrading to version 5.0.1

from authpermissions.aspnetcore.

JonPSmith avatar JonPSmith commented on July 20, 2024

Hi @rr222cy,

Sorry to hear that 5.0.1 has a problem. I have tried Example6, which has sharding turned on, and it worked. Can you tell me:

  • What type of sharding are you using? Hybrid or sharding only (i.e. every tenant has its own database)?
  • Does your app got a shardingsettings.Development,json file already created?
  • What triggers the exception - startup, changing the sharding data, adding a new tenant, etc.?

from authpermissions.aspnetcore.

roos-robert avatar roos-robert commented on July 20, 2024

Hi @JonPSmith,

Thank you for the quick reply and also a big thanks for your work on AuthP!

Your reply made me realize that I was missing the file "shardsettings.Development.json", the one I had was "shardsettings.json". So no problem at all with 5.0.1, the issue was I was lacking this file- which seems to have worked fine before, but now (correctly) triggered an exception.

Just as a reference and to answer your question, what made the exception trigger was when trying to read/manipulate any data at all, which makes perfect sense now since this file and contents were missing. And the type of sharding used is hybrid.

Thanks again and take care!

from authpermissions.aspnetcore.

roos-robert avatar roos-robert commented on July 20, 2024

Hi again @JonPSmith,

It seems I was a bit to quick to put this issue as solved. While the issue is solved locally, I face the same issue now when trying to publish the application to my staging server (Windows Server, IIS). The error i get is the following:

Category: Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer EventId: 2 SpanId: 602148485bbcf686 TraceId: c54da5f16ec76b87d447a9b5270f86aa ParentId: 0000000000000000 RequestId: 40000090-0001-fd00-b63f-84710c7967bb RequestPath: /api/auth/login Connection ID "18230571296696041615", Request ID "40000090-0001-fd00-b63f-84710c7967bb": An unhandled exception was thrown by the application. Exception: System.ArgumentNullException: Value cannot be null. (Parameter 'source') at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) at System.Linq.Enumerable.Any[TSource](IEnumerable1 source) at AuthPermissions.AspNetCore.ShardingServices.ShardingConnectionsJsonFile.GetDatabaseInformation() at AuthPermissions.AspNetCore.ShardingServices.ShardingConnectionsJsonFile.FormConnectionString(String databaseInfoName) at AuthPermissions.AspNetCore.GetDataKeyCode.GetShardingDataUserNormal..ctor(IHttpContextAccessor accessor, IShardingConnections connectionService) at ResolveService(ILEmitResolverBuilderRuntimeContext, ServiceProviderEngineScope) at ResolveService(ILEmitResolverBuilderRuntimeContext, ServiceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired) at lambda_method440(Closure, IServiceProvider, Object[]) at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at AuthPermissions.SupportCode.DownStatusCode.RedirectUsersViaStatusData.RedirectUserOnStatusesAsync(ClaimsPrincipal user, Action1 redirect, Func1 next) at AuthPermissions.SupportCode.DownStatusCode.RegisterDownForMaintenance.<>c__DisplayClass0_0.<<UseDownForMaintenance>b__0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT1.ProcessRequestAsync()

I've checked on the server that the shardsettings file exists and has the correct values:

{
  "ShardingDatabases": [
    {
      "Name": "Default Database",
      "DatabaseName": null,
      "ConnectionName": "DefaultConnection",
      "DatabaseType": "SqlServer"
    }
  ]
}

The .json file is placed in the same root directory on the server as where the appsettings.json file is located. This works when running the MVC app locally (roslyn, Rider IDE) with the exact same setup. But breaks upon publish to IIS.

Has there been some changes in how this file is located perhaps that is causing this? Looking through the source code it seems (if I understand your comments correctly) that shardsettings should not even be necessary (like in 5.0.0), but instead if it does not exist, will default to the "DefaultConnection" value. Which is probably why my app before 5.0.1 was working, but after the changes not.

Thanks in advance for any hints on how to solve this! 😊

from authpermissions.aspnetcore.

roos-robert avatar roos-robert commented on July 20, 2024

Hi again @JonPSmith,

Thank you once again for the very comprehensive answer and explanation! One of the things I love about AuthP, not just documentation/comments saying what to do- but also why and how stuff works.

I completely understand now the issue and why things were working before, but really should not have (causing issues later on).

I followed your recommendation on how to fix the mismatch, there was indeed a mismatch on the server in the shardsettings.Production.json file. After adding the missing information the application instantly came back online in my staging environment and everything is now working great again!

Thanks again for taking the time to answer, explain the issue and give a great solution. 😊

from authpermissions.aspnetcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.