azure - 使用 Azure KeyVault 添加 session 状态提供程序作为连接字符串

标签 azure caching redis session-state-provider

目前我正在尝试在我的项目中添加 MS Session State Provider:https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-aspnet-session-state-provider

设置如下:

<sessionState mode="Custom" customProvider="MySessionStateStore">
      <providers>
        <!-- For more details check https://github.com/Azure/aspnet-redis-providers/wiki -->
        <!-- Either use 'connectionString' OR 'settingsClassName' and 'settingsMethodName' OR use 'host','port','accessKey','ssl','connectionTimeoutInMilliseconds' and 'operationTimeoutInMilliseconds'. -->
        <!-- 'throwOnError','retryTimeoutInMilliseconds','databaseId' and 'applicationName' can be used with both options. -->
        <!--
          <add name="MySessionStateStore" 
            host = "127.0.0.1" [String]
            port = "" [number]
            accessKey = "" [String]
            ssl = "false" [true|false]
            throwOnError = "true" [true|false]
            retryTimeoutInMilliseconds = "5000" [number]
            databaseId = "0" [number]
            applicationName = "" [String]
            connectionTimeoutInMilliseconds = "5000" [number]
            operationTimeoutInMilliseconds = "1000" [number]
            connectionString = "<Valid StackExchange.Redis connection string>" [String]
            settingsClassName = "<Assembly qualified class name that contains settings method specified below. Which basically return 'connectionString' value>" [String]
            settingsMethodName = "<Settings method should be defined in settingsClass. It should be public, static, does not take any parameters and should have a return type of 'String', which is basically 'connectionString' value.>" [String]
            loggingClassName = "<Assembly qualified class name that contains logging method specified below>" [String]
            loggingMethodName = "<Logging method should be defined in loggingClass. It should be public, static, does not take any parameters and should have a return type of System.IO.TextWriter.>" [String]
            redisSerializerType = "<Assembly qualified class name that implements Microsoft.Web.Redis.ISerializer>" [String]
          />
        -->
        <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="" accessKey="" ssl="true" />
      </providers>
    </sessionState>

但是,我们不想在 web.config 文件中公开带有访问 key 的连接字符串。为此,我们使用 Azure KeyVault。

有什么方法可以将 Azure KeyVault 与 session 状态提供程序结合使用?

非常感谢!

最佳答案

settingsClassName 和 settingsMethodName 设置可用于提供返回连接字符串的类和方法。您定义的此方法可以转向 KeyVault 并返回所需的连接字符串。

How to use configuration parameters of Session State Provider and Output Cache Provider

关于azure - 使用 Azure KeyVault 添加 session 状态提供程序作为连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55366193/

相关文章:

azure - Azure 中服务主体和托管身份之间的区别

c# - 我可以迭代 .NET4 MemoryCache 吗?

java - 在 Java 客户端中使用缓存控制 header

compression - 在将字符串放入 redis 之前压缩字符串 - 这有意义吗?

与 ADFS 集成时 Azure AD B2C 异常

Azure API 管理到 VNet

azure - 禁用 Azure 应用服务的外部 IP

java - 将缓存放在分布式 Redis 缓存的前面

azure - 什么是 Azure Redis 缓存?

docker - 无法启动和连接3个docker服务-Redis,Python 3.7 Slim(Running DRF)和Celery