zoukankan      html  css  js  c++  java
  • .net core MVC 集群DataProtection

    .net core 分布式部署时,不使用Session,使用Redis+Cookie存储数据,

    但是会涉及到DataProtection的使用;

    解决方法使用DataProtection到持续化到Redis中;

    Redis 不能使用Microsoft.Extensions.Caching.Redis 包,会有包冲突,使用 Microsoft.Extensions.Caching.StackExchangeRedis

    然后使用
    Microsoft.AspNetCore.DataProtection.StackExchangeRedis包

     然后在 ConfigureServices 方法中进行如下配置

    #region DataProtection
    //设置应用程序唯一标识
    var redis =StackExchange.Redis.ConnectionMultiplexer.Connect(Configuration["Redis:Server"]);
    services.AddDataProtection().SetApplicationName("APPIdentityName")
    .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");
    #endregion

    #region Redis配置
    services.AddSingleton<StackExchange.Redis.IConnectionMultiplexer>(StackExchange.Redis.ConnectionMultiplexer.Connect(Configuration["Redis:Server"]));
    services.AddStackExchangeRedisCache(options => {
    options.Configuration = Configuration["Redis:Server"]; //数据库配置的Redis连接字符串
    options.InstanceName = Configuration["Redis:InstanceName"];//Redis实例名称
    });
    #endregion

  • 相关阅读:
    NKOI 1363 (基础二分)
    POJ 1321 棋盘问题(dfs八皇后变形)
    UVA 1368 DNA(模拟+贪心)
    暴力(解数阵)
    A Linear Algebra Problem(唯一性的判定)
    hdu 1565 方格取数(1)
    hdu 1074 Doing Homework
    hdu 1233 还是畅通工程
    hdu 1232 畅通工程
    hdu 1213 How Many Tables
  • 原文地址:https://www.cnblogs.com/ruiying/p/13164484.html
Copyright © 2011-2022 走看看