Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overide Connection for RedisSessionStateProvider on Azure

i am using RedisSessionStateProvider with asp.net mvc 4.5 for session management. i am using azure web app for my hosting. how do i override this connection info on azure portal during prod deployment. is there any other way than using web.release.config transform file?

  <sessionState mode="Custom" timeout="2000" customProvider="MySessionStateStore">
    <providers>
      <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="server.cloudapp.net" port="6379" accessKey="password" ssl="false" databaseId="1" applicationName="pWeb" />
    </providers>
  </sessionState>
like image 896
Justin Homes Avatar asked Feb 09 '23 10:02

Justin Homes


1 Answers

The provider takes in a ConnectionString parameter which can point to an appsetting. You can set this appsetting based on the environment you are running in. The following code shows the web.config

<appSettings>
    <add key="RedisConnection" value="cachename.redis.cache.windows.net,ssl=true,password=password"/>
  </appSettings>
    <sessionState mode="Custom" customProvider="MySessionStateStore">
      <providers>
        <add name="MySessionStateStore" 
             type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="RedisConnection"/>
      </providers>
    </sessionState>
like image 78
pranav rastogi Avatar answered Feb 11 '23 23:02

pranav rastogi