5

Asp.net mvc 5 application web config file is

   sessionState mode="Custom" customProvider="RedisSessionProvider">
      providers>
add name="RedisSessionProvider" type="Microsoft.Web.Redis.RedisSessionStateProvider" port="6380" host="XXX.redis.cache.windows.net" accessKey="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ssl="true" />
 providers>
    sessionState>

When i run application have eror

Server Error in '/' Application.
No connection is available to service this operation: EVAL
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: StackExchange.Redis.RedisConnectionException: No connection is available to service this operation: EVAL
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[RedisConnectionException: No connection is available to service this operation: EVAL]
   StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl(Message message, ResultProcessor`1 processor, ServerEndPoint server) in c:\TeamCity\buildAgent\work\3ae0647004edff78\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:1922
   StackExchange.Redis.RedisBase.ExecuteSync(Message message, ResultProcessor`1 processor, ServerEndPoint server) in c:\TeamCity\buildAgent\work\3ae0647004edff78\StackExchange.Redis\StackExchange\Redis\RedisBase.cs:80
   StackExchange.Redis.RedisDatabase.ScriptEvaluate(String script, RedisKey[] keys, RedisValue[] values, CommandFlags flags) in c:\TeamCity\buildAgent\work\3ae0647004edff78\StackExchange.Redis\StackExchange\Redis\RedisDatabase.cs:866
   Microsoft.Web.Redis.<>c__DisplayClass4.<Eval>b__3() in c:\TeamCity\buildAgent\work\f55792526e6d9089\src\Shared\StackExchangeClientConnection.cs:113
   Microsoft.Web.Redis.StackExchangeClientConnection.RetryForScriptNotFound(Func`1 redisOperation) in c:\TeamCity\buildAgent\work\f55792526e6d9089\src\Shared\StackExchangeClientConnection.cs:129
   Microsoft.Web.Redis.StackExchangeClientConnection.RetryLogic(Func`1 redisOperation) in c:\TeamCity\buildAgent\work\f55792526e6d9089\src\Shared\StackExchangeClientConnection.cs:155
   Microsoft.Web.Redis.StackExchangeClientConnection.Eval(String script, String[] keyArgs, Object[] valueArgs) in c:\TeamCity\buildAgent\work\f55792526e6d9089\src\Shared\StackExchangeClientConnection.cs:113
   Microsoft.Web.Redis.RedisConnectionWrapper.Set(ISessionStateItemCollection data, Int32 sessionTimeout) in c:\TeamCity\buildAgent\work\f55792526e6d9089\src\RedisSessionStateProvider\RedisConnectionWrapper.cs:135
   Microsoft.Web.Redis.RedisSessionStateProvider.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, Object lockId, Boolean newItem) in c:\TeamCity\buildAgent\work\f55792526e6d9089\src\RedisSessionStateProvider\RedisSessionStateProvider.cs:408
   System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) +906
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +142
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +92
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0
worldofjr
  • 3,868
  • 8
  • 37
  • 49
Ivan
  • 577
  • 2
  • 9
  • 14

4 Answers4

6

I had the same, and eventually fixed it by adding sslprotocols=tls12 to the connectionstring. It should not be necessary, but apparently it is, using recently created Redis caches on Azure. Probably due to the deprecation of TLS 1.0 and 1.2

DdW
  • 890
  • 1
  • 18
  • 30
3

Could be for 3 reasons:

  1. Your connection string is wrong (looks ok any way)
  2. The instance isn't yet created (usually takes a lot to be created in azure)
  3. You are facing firewall (including windows firewall) issues

Are you able to get connected to the redis cache instance using command prompt?

Download redis for windows Here

and then run

redis-cli -h XXX.redis.cache.windows.net -a XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 

You can find here a detailed demo (in spanish but console demos remains usable.)

NinjaTip #18 - Introducción a Redis

For testing purposes ensure than Redis service has port 6379 open (this is the non SSl port option you need to enable on azure)

If you can't connect to your instance is because some of the reasons listed above.

Community
  • 1
  • 1
JuanK
  • 2,056
  • 19
  • 32
  • i check connection string and its ok,check instance wzs created.Can you help me how to change firewall on azure server? – Ivan Dec 12 '15 at 16:58
  • Isn't azure firewall. See local firewall or Windows firewall – JuanK Dec 12 '15 at 21:08
  • firewall is disabled. – Ivan Dec 14 '15 at 08:01
  • Are you able to get connected to the redis cache instance using command prompt? – JuanK Dec 14 '15 at 12:42
  • No,I added redis cache from azure portal. – Ivan Dec 14 '15 at 13:38
  • That's what I mean, You should be able to connect to Azure Redis Instance using command prompt from your local machine as I show you in the example above. I also have added a link to a video exploring redis connection on azure. – JuanK Dec 14 '15 at 13:44
  • Hi @Ivan Did It work? Do you have more info related to this issue? – JuanK Dec 16 '15 at 14:03
2

I had the same issue before and I found a solution that using another one: https://github.com/alex-simonov/RedisAspNetProviders

This one works for me

Roy Pun
  • 493
  • 4
  • 8
1

I found that only the following configuration in web config works for me:

<sessionState mode="Custom" customProvider="MySessionStateStore">
  <providers>
    <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="PUTCORRECTNAMEHERE.edis.cache.windows.net:6380,password=YOURPRIMARYKEYPUTHERE,ssl=True,abortConnect=False" />
  </providers>
</sessionState>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
NickA
  • 21
  • 6