简体   繁体   中英

Can't connect to Redis server using ASP.NET Session State Provider

I have been attempting to replace ASP.NET Session with Redis for some time now. Multiple hours with the Microsoft ASP.NET Session State Provider for Redis have been fruitless.

We have an on-premises Sentinel configuration for Redis. Originally I thought this was not working due to the Provider not supporting Sentinels. I switched my connection string to use the master, in hopes that I would at least be able to establish a connection. Still nothing.

I have tried multiple configurations for this provider and continually receive either "No connection available for the request" or "Additional information: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. UnableToResolvePhysicalConnection on PING."

Here are some of the configurations I've attempted:

Attempt #1:

<connectionStrings>
  <add name="RedisConnection" connectionString="1.2.3.4:5,abortConnect=false,ssl=true,password=XXXXXX,ConnectTimeout=10000"/>
</connectionStrings>

<sessionState mode="Custom" customProvider="MySessionStateStore">
  <providers>
    <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="RedisConnection" />
  </providers>
</sessionState>

Attempt #2:

<sessionState mode="Custom" customProvider="MySessionStateStore">
  <providers>
    <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="1.2.3.4" port="5" accessKey="XXXXXXX" />
  </providers>
</sessionState>

Attempt #3:

<sessionState mode="Custom" customProvider="MySessionStateStore">
  <providers>
    <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="1.2.3.4:5" accessKey="XXXXXXX" />
  </providers>
</sessionState>

I have found very little documentation on this provider, and troubleshooting has been a challenge. I came across a third-party provider and decided to try it, compared to the Microsoft provider.

I was able to successfully connect with Harbour.RedisSessionStateStore , using the following configuration:

<sessionState mode="Custom" customProvider="RedisSessionStateProvider">
  <providers>
    <clear />
    <add name="RedisSessionStateProvider" type="Harbour.RedisSessionStateStore.RedisSessionStateStoreProvider" host="PASSWORD@1.2.3.4:5" clientType="pooled" />
  </providers>
</sessionState>

With this is mind, what is the correct format for a connection string for the Microsoft provider? It will be easier for me to receive internal support from a first party library, and at this point, it would be a moral victory to get this working.

Also, if anyone knows how I could configure this to hit the Sentinel and determine the master instance to connect to, I would welcome a blog post or any sort of knowledge share on the topic.

Thank you!

I can give you an example of a working configuration, which we have in our production, no sentinel, but directly to the master:

<system.web>
  <sessionState mode="Custom" customProvider="Custom_RedisSessionStateStore">
    <providers>
    <add name="Custom_RedisSessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="your_host_name_goes_here" accessKey="" port="6379" ssl="false" operationTimeoutInMilliseconds="5000" />
    </providers>
  </sessionState>
</system.web>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM