【发布时间】:2014-05-11 13:04:29
【问题描述】:
我正在尝试从 Visual Studio Web 项目连接到 Azure Redis 缓存(预览版)的实例。
我收到以下错误:“无法加载文件或程序集'用户传递的授权令牌无效”。
我做了以下事情: 1) 登录 Azure Portal 并创建一个新的 Redis Cache PREVIEW 2)打开Visual Studio并创建新项目(Web MVC) 3) 管理 Nuget 包 - 全部更新 4) 安装包 - “Windows Azure 缓存版本 2.2.0.0” 5)打开Web.Config,在dataCacheClients部分如下:
<dataCacheClients>
<dataCacheClient name="default">
<autoDiscover isEnabled="true" identifier="mycache.redis.cache.windows.net" />
<securityProperties mode="Message" sslEnabled="false">
<messageSecurity authorizationInfo="xxxxxxxmykeyxxxxxxxx"/>
</securityProperties>
</dataCacheClient>
</dataCacheClients>
6) 将 HomeController.cs 更改为以下内容:
using Microsoft.ApplicationServer.Caching;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace CacheRedisTest.Controllers
{
public class HomeController : Controller
{
static DataCacheFactory myFactory;
static DataCache myCache;
public ActionResult Index()
{
if (myCache == null)
{
myFactory = new DataCacheFactory();
myCache = myFactory.GetDefaultCache();
}
return View();
}
}
}
我是否需要一些其他特定于 Redis 的 nuget 包?另外我应该把 Azure 控制台中提到的端口号放在哪里?
感谢阅读
【问题讨论】:
-
比这更容易,您不需要 DataCacheFactory - 使用 ConnectionMultiplexer 。见azure.microsoft.com/blog/2014/06/05/…
标签: asp.net redis azure-caching