微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

UnableToConnect Azure Redis缓存

如何解决UnableToConnect Azure Redis缓存

我正在尝试将ASP.NET会话状态存储在缓存中(用于Redis的Azure缓存),如此处https://docs.microsoft.com/en-us/azure/azure-cache-for-redis/cache-aspnet-session-state-provider

所述

但是,我收到以下错误消息。

mydomain.redis.cache.windows.net:6379/Interactive上的UnabletoConnect, 原点:ResetNonConnected,输入缓冲区:0,未完成:0,最后读取: 5s之前,最后写入:5s之前,未答复写入:1106595s之前, 保持活动状态:60秒钟,待处理状态:0,状态:正在连接,最后一次心跳:从不, last-mbeat:-1s之前,global:5s之前,mgr:无效,err:永不 StackExchange.Redis.RedisConnectionException:无法连接 mydomain.redis.cache.windows.net:6379/Interactive,来源: ResetNonConnected,输入缓冲区:0,未完成:0,最后读取:5秒钟前, 上次写入:5s前,未答复写入:1106595s前,保持活动状态:60s, 待定:0,状态:正在连接,最后一次心跳:从不,最后一次心跳:-1秒 前,全球:5年前,mgr:不活跃,错误:从不

    <add name="AzureRedisCacheConnection" connectionString="mydomain.redis.cache.windows.net:6379,password=password=,ssl=False,abortConnect=False"/>
  </connectionStrings>
  
  
  <sessionState mode="Custom" customProvider="AzureCacheForRedisProvider">
      <providers>
        <!-- For more details check https://github.com/Azure/aspnet-redis-providers/wiki -->
        <!-- Either use 'connectionString' OR 'settingsClassName' and 'settingsMethodName' OR use 'host','port','accessKey','ssl','connectionTimeoutInMilliseconds' and 'operationTimeoutInMilliseconds'. -->
        <!-- 'throwOnError','retryTimeoutInMilliseconds','databaseId' and 'applicationName' can be used with both options. -->
        <!--
          <add name="AzureCacheForRedisProvider" 
            host = "127.0.0.1" [String]
            port = "" [number]
            accessKey = "" [String]
            ssl = "false" [true|false]
            throwOnError = "true" [true|false]
            retryTimeoutInMilliseconds = "5000" [number]
            databaseId = "0" [number]
            applicationName = "" [String]
            connectionTimeoutInMilliseconds = "5000" [number]
            operationTimeoutInMilliseconds = "1000" [number]
            connectionString = "<Valid StackExchange.Redis connection string>" [String]
            settingsClassName = "<Assembly qualified class name that contains settings method specified below. Which basically return 'connectionString' value>" [String]
            settingsMethodName = "<Settings method should be defined in settingsClass. It should be public,static,does not take any parameters and should have a return type of 'String',which is basically 'connectionString' value.>" [String]
            loggingClassName = "<Assembly qualified class name that contains logging method specified below>" [String]
            loggingMethodName = "<Logging method should be defined in loggingClass. It should be public,does not take any parameters and should have a return type of System.IO.TextWriter.>" [String]
            redisSerializerType = "<Assembly qualified class name that implements Microsoft.Web.Redis.ISerializer>" [String]
          />
        -->
        <add name="AzureCacheForRedisProvider" type="Microsoft.Web.Redis.RedisSessionStateProvider"
                     connectionString="AzureRedisCacheConnection" 
           
             />
      </providers>
    </sessionState> ````



What am I missing here?

解决方法

我已经阅读了官方文档,并且对我有用

如果要支持6379,则需要设置Allow access only via SSL=Noenter image description here

我也找到了这些官方博客,我认为这对您有用。

Announcing ASP.NET Session State Provider for Redis Preview Release

我的web.config文件中的内容。

<sessionState mode="Custom" customProvider="MySessionStateStore">
  <providers>
    <!-- For more details check https://github.com/Azure/aspnet-redis-providers/wiki -->
    <!-- Either use 'connectionString' OR 'settingsClassName' and 'settingsMethodName' OR use 'host','port','accessKey','ssl','connectionTimeoutInMilliseconds' and 'operationTimeoutInMilliseconds'. -->
    <!-- 'throwOnError','retryTimeoutInMilliseconds','databaseId' and 'applicationName' can be used with both options. -->
    <!--
      <add name="MySessionStateStore" 
        host = "127.0.0.1" [String]
        port = "" [number]
        accessKey = "" [String]
        ssl = "false" [true|false]
        throwOnError = "true" [true|false]
        retryTimeoutInMilliseconds = "5000" [number]
        databaseId = "0" [number]
        applicationName = "" [String]
        connectionTimeoutInMilliseconds = "5000" [number]
        operationTimeoutInMilliseconds = "1000" [number]
        connectionString = "<Valid StackExchange.Redis connection string>" [String]
        settingsClassName = "<Assembly qualified class name that contains settings method specified below. Which basically return 'connectionString' value>" [String]
        settingsMethodName = "<Settings method should be defined in settingsClass. It should be public,static,does not take any parameters and should have a return type of 'String',which is basically 'connectionString' value.>" [String]
        loggingClassName = "<Assembly qualified class name that contains logging method specified below>" [String]
        loggingMethodName = "<Logging method should be defined in loggingClass. It should be public,does not take any parameters and should have a return type of System.IO.TextWriter.>" [String]
        redisSerializerType = "<Assembly qualified class name that implements Microsoft.Web.Redis.ISerializer>" [String]
      />
    -->
    <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="jasonp2rediscache.redis.cache.windows.net:6380" accessKey="kKtOl***kLPg=" ssl="true" />
  </providers>
</sessionState>

我的测试步骤。

步骤1。在登录方法中添加Session["loginTime"]

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Login(LoginViewModel model,string returnUrl)
    {
        if (!ModelState.IsValid)
        {
            return View(model);
        }

        // This doesn't count login failures towards account lockout
        // To enable password failures to trigger account lockout,change to shouldLockout: true
        var result = await SignInManager.PasswordSignInAsync(model.Email,model.Password,model.RememberMe,shouldLockout: false);
        switch (result)
        {
            case SignInStatus.Success:
                Session["loginTime"] = DateTime.Now.ToString();// Add this line
                Session["webapp"] = "mywebapp";// Add this line
                return RedirectToLocal(returnUrl); 
            case SignInStatus.LockedOut:
                return View("Lockout");
            case SignInStatus.RequiresVerification:
                return RedirectToAction("SendCode",new { ReturnUrl = returnUrl,RememberMe = model.RememberMe });
            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("","Invalid login attempt.");
                return View(model);
        }
    }

enter image description here

步骤2.通过redsmin连接您的Redis缓存。 (https://app.redsmin.com/

我已经在该网站注册以检查价值。

第3步。运行项目。

enter image description here

第4步。检查键和Redsmin中的值。

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?