mrellipse / toucan

Boilerplate template using Vue.js, TypeScript and .NET Core 2.1, based on SOLID design principles
MIT License
212 stars 36 forks source link

Application payload Error. #10

Closed hmuhdkamran closed 6 years ago

hmuhdkamran commented 6 years ago

After updating the application, and generating a new build, It start an error on login, : Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgery[7] An exception was thrown while deserializing the token. System.InvalidOperationException: The antiforgery token could not be decrypted. ---> System.Security.Cryptography.CryptographicException: The payload was invalid. at Microsoft.AspNetCore.DataProtection.Managed.ManagedAuthenticatedEncryptor.Decrypt(ArraySegment1 protectedPayload, ArraySegment1 additionalAuthenticatedData)

second when I use dbContext.Database.ExecuteCommandAsync('Any procedure') at first it work ok, and on next attempt It gives Database connection closed.

mrellipse commented 6 years ago

as you are hosting it on ubuntu, you will need to explicitly configure DataProtection similar to below

public static partial class Extensions { public static void ConfigureDataProtection(this IServiceCollection services, Toucan.Server.Config config) { services.AddDataProtection() .PersistKeysToFileSystem(new DirectoryInfo("/var/lib/toucan/web/keys")) .SetApplicationName(config.ApplicationName); } } otherwise the keys used to encrypt and decrypt token details will change each time the app is restarted. this is just a part of AspNetCore setup in general that developers need to learn about.

i haven't run into the other issue you mentioned regarding database connection being closed. but I believe it might be a bug.

can you try changing the StructureMap registration for DbContextBase in the Server project to be ContainerScoped() and let me know if behaviour alters?

the default service.AddDbContext() should be creating the correct registration as per

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection

but the subsequent registration might be clashing with that as it builds up an IServiceProvider instance

hmuhdkamran commented 6 years ago

It has been resolved, the issue was that the folder have not sufficient rights, now it is working fine.