1

Currently I am trying to add MS Session State Provider in my project: https://docs.microsoft.com/en-us/azure/azure-cache-for-redis/cache-aspnet-session-state-provider

The settings are like this:

<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>

However, we don't want to expose our connection string with access key in our web.config file. We are using Azure KeyVault for this.

Is there any way I can use Azure KeyVault with Session State Provider?

Many Thanks!

Terence
  • 522
  • 7
  • 24

1 Answers1

3

The settingsClassName and settingsMethodName settings can be used to provide a Class and method that return the connection string. This method that you define can turn around to KeyVault and return the required connection string.

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

Carl Dacosta
  • 760
  • 3
  • 12
  • Good stuff! It seems I have to use both `settingsClassName` and `settingsMethodName`. btw, what does `Assembly qualified class name` mean? Where should I declare my class and method? – Terence Mar 27 '19 at 00:13
  • For detail implementation, we can refer to this answer: https://stackoverflow.com/a/48566488/3283323 – Terence Mar 27 '19 at 18:55