How to determine connection string for session state in Azure

I use RedisSessionStateProviderusing this method https://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-session-state-caching/

I define its connection string in web.config, in this example XXXXXX.

 <system.web>
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.5" />
    <globalization culture="es-CO" uiCulture="es" />
    <customErrors mode="Off" />
    <sessionState mode="Custom" customProvider="SessionStateStore">
      <providers>
        <add name="SessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="XXXXXX" throwOnError="true" applicationName="NominappSession" />
      </providers>
    </sessionState>
  </system.web>

I do not want to put the connection string in the source code. So how can I use settings in Azure to define this connection string?

I am deploying on azure from github, so it uses Kudu. I do not have an external CI server.

Any tips please?

+4
source share
4 answers

I did it :)

, . sesion .

:

  <appSettings>
    <add key="REDIS_CONNECTION_STRING" value="redis,allowAdmin=true" />
  </appSettings>
  <system.web>
    <sessionState mode="Custom" customProvider="SessionStateStore">
      <providers>
        <add name="SessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="REDIS_CONNECTION_STRING" applicationName="REDIS_SESSION_APPLICATION_NAME" throwOnError="true" />
      </providers>
    </sessionState>
  </system.web>

, Azure WebSites

+3

, IPartitionResolver ...

, System.Web.IPartitionResolver sessin web.config

<sessionState mode="Custom"  partitionResolverType="WebAppConnectionStringResolver">

public class WebAppConnectionStringResolver : System.Web.IPartitionResolver
{
   public void Initialize()
   {

   }

   public string ResolvePartition(object key)
   {
     return System.Configuration.ConfigurationManager.ConnectionStrings["your_Conn_string_name_in_portal"]
   }
}

, ,

0

, settingsClassName settingsMethodName , :

 <sessionState mode="Custom" customProvider="RedisSessionStateStore">
  <providers>
      <add
        name="RedisSessionStateStore"
        type="Microsoft.Web.Redis.RedisSessionStateProvider"
        settingsClassName="MyApp.SessionStateRedisSettings,MyApp"
        settingsMethodName="ConnectionString" />
  </providers>

, settingsClassName - . settingsMethod - , , 0 . :

namespace MyApp
{
    public static class SessionStateRedisSettings
    {
        public static string ConnectionString()
        {
            return "ConnectionString goes here";
        }
    }
}

: https://github.com/Azure/aspnet-redis-providers/wiki/Configuration

0

Source: https://habr.com/ru/post/1629720/


All Articles