【问题标题】:Set Windows Azure Redis connection string on the portal在门户上设置 Windows Azure Redis 连接字符串
【发布时间】:2016-09-13 12:04:19
【问题描述】:

在我维护了2个Redis连接字符串的redis辅助方法上。一个用于local,另一个用于Azure redis server。每次我需要发布时,我都必须手动更改它。我的应用是 ASP.net MVC (SPA) 应用。

问:那么有没有什么地方可以在 Azure 门户上或我发布时设置已发布的Redis connection string

 public class RedisConnectorHelper
    {
     private static readonly Lazy<ConnectionMultiplexer> LazyConnection =
            new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect("localhost,ConnectTimeout=10000"));//local host

     //private static readonly Lazy<ConnectionMultiplexer> LazyConnection =
     //   new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect("Myredis.redis.cache.windows.net:6380,password=mypassword,ssl=True,abortConnect=False"));//production
} 

更新:

我已经在web.config.release 文件上设置了,如下所示。

<connectionStrings>

    <add name="Abp.Redis.Cache" connectionString="Myredis.redis.cache.windows.net:6380,password=mypassword=,ssl=True,abortConnect=False" />

  </connectionStrings>

但它似乎没有捡起它。你能告诉我为什么吗?

【问题讨论】:

  • 您的应用程序是如何部署的 - Web 应用程序、云服务还是在 VM 中?
  • @GauravMantri Web Apps
  • 您可以查看 web.config 转换并将适当的连接字符串放入 web.config.release 文件中。因此,当应用程序以“发布”模式构建时,它会从那里获取正确的连接字符串。
  • @GauravMantri 除了db connection string 之外,它还会选择Redis connection string 吗?
  • 是的,它应该把它捡起来。

标签: asp.net-mvc azure redis stackexchange.redis


【解决方案1】:

这是诀窍。干杯:)

#if DEBUG
   private static readonly Lazy<ConnectionMultiplexer> LazyConnection =
            new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect("localhost,ConnectTimeout=10000"));//local host
#else
   private static readonly Lazy<ConnectionMultiplexer> LazyConnection =
      new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect("Myredis.redis.cache.windows.net:6380,password=mypassword,ssl=True,abortConnect=False"));//production
#endif

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    • 2018-08-15
    • 1970-01-01
    • 2016-03-24
    相关资源
    最近更新 更多