【发布时间】:2015-01-24 20:49:20
【问题描述】:
我一直在尝试让 WebApi 与 Sitecore 7.5 一起工作(我能够让相同的代码与 7.2 一起工作)
我在配置中留下了对MVC 5.1 的引用
和
当我尝试访问使用属性映射的路由时出现以下异常:
[RoutePrefix("test/api/Other")]
[Route("{action=Get}")]
public class OtherController : ApiController
{
[HttpGet]
public string GetId()
{
return "test";
}
}
消息:“发生错误。”,ExceptionMessage:“值不能 空值。参数名称:key”,异常类型: “System.ArgumentNullException”,堆栈跟踪:“在 System.Collections.Generic.Dictionary
2.FindEntry(TKey key) at System.Collections.Generic.Dictionary2.TryGetValue(TKey key, TValue& 值)在 Sitecore.Services.Infrastructure.Web.Http.Dispatcher.NamespaceHttpControllerSelector.SelectController(HttpRequestMessage 请求)在 System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage 请求,CancellationToken 取消令牌)在 System.Web.Http.Dispatcher.HttpControllerDispatcher.d__0.MoveNext()"
我在应用程序启动中的代码如下:
protected void Application_Start(object sender, EventArgs e)
{
GlobalConfiguration.Configure(ConfigureRoutes);
}
public static void ConfigureRoutes(HttpConfiguration config)
{
GlobalConfiguration.Configuration.MapHttpAttributeRoutes();
GlobalConfiguration.Configuration.Formatters.Clear();
GlobalConfiguration.Configuration.Formatters.Add(new JsonMediaTypeFormatter());
}
任何帮助将不胜感激......
【问题讨论】:
-
您是否在 Sitecore 的 IgnoreUrlPrefixes 设置中添加了路由前缀(本例中为“test/api”)?
-
是的,我刚刚尝试将路由前缀添加到 IngnoreUrlPrefix,但它仍然无法正常工作......有趣的是相同的代码在干净的 7.2 实例中工作,我认为新的 DI Sitecore.Services.Infrastructure.Web.Http.Dispatcher.NamespaceHttpControllerSelector.SelectController 出现对象引用错误
-
我认为问题出在属性路由中,获取和对象引用在哪里,使其工作的唯一方法不是使用属性路由,而是使用经典路由,我正在谈论它帖子:sitecorecommerce.wordpress.com/2014/11/30/…
-
我也有同样的问题。从 Sitecore 7.2 升级到 7.5,通过 web api 请求时出现相同的错误。
-
你们知道这是否在最新的 7.5 版本中修复了吗?
标签: sitecore sitecore7 asp.net-apicontroller sitecore-mvc sitecore7.5