【问题标题】:Adding Session State Provider using Azure KeyVault for the connection string使用 Azure KeyVault 为连接字符串添加会话状态提供程序
【发布时间】:2023-04-07 18:58:01
【问题描述】:

目前我正在尝试在我的项目中添加 MS 会话状态提供程序:https://docs.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 文件中使用访问密钥公开我们的连接字符串。为此,我们使用 Azure KeyVault。

有什么方法可以将 Azure KeyVault 与会话状态提供程序一起使用?

非常感谢!

【问题讨论】:

    标签: azure caching redis session-state-provider


    【解决方案1】:

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

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

    【讨论】:

    • 好东西!看来我必须同时使用settingsClassNamesettingsMethodName。顺便说一句,Assembly qualified class name 是什么意思?我应该在哪里声明我的类和方法?
    • 具体实现可以参考这个答案:stackoverflow.com/a/48566488/3283323
    猜你喜欢
    • 2011-07-22
    • 2016-06-02
    • 2013-07-21
    • 2012-08-23
    • 2011-06-23
    • 2015-03-10
    • 2015-11-18
    • 2013-06-11
    • 2016-04-19
    相关资源
    最近更新 更多