How to implement machineKey in ASP.NET Core 2.0

后端 未结 4 559
傲寒
傲寒 2020-12-03 16:50

In ASP.NET (not core) I would normally add a machineKey to the web.config so that I could perform some functions on a local machine instead of the server so that database/ca

4条回答
  •  自闭症患者
    2020-12-03 17:28

    You can find good examples at https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/implementation/key-storage-providers?view=aspnetcore-2.2&tabs=visual-studio

    I used my database context to persist the keys across multiple instances.

    DbContext.cs

    public class MyContext : IDataProtectionKeyContext
    {
      ...
      // This maps to the table that stores keys.
      public DbSet DataProtectionKeys { get; set; }
    }
    

    Startup.cs

    public void ConfigureServices(IServiceCollection services)
    {
      ...
      services.AddDataProtection().PersistKeysToDbContext();
    }
    

提交回复
热议问题