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

匿名 (未验证) 提交于 2019-12-03 00:57:01

问题:

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!

回答1:

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> 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!