gpt4 book ai didi

sitecore - 升级到 sitecore 8 后,WEB API 调用出现 500 错误

转载 作者:行者123 更新时间:2023-12-02 19:20:51 25 4
gpt4 key购买 nike

最近,我们从 Sitecore 7.5 升级到了 Sitecore 8.0。升级后,自定义 Web API 调用开始返回 500 个错误代码,但存在以下异常:

Message:"An error has occurred."
ExceptionMessage:"ValueFactory attempted to access the Value property of this instance."
ExceptionType:"System.InvalidOperationException"
StackTrace:" at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.GetControllerMapping()
at System.Web.Http.Routing.AttributeRoutingMapper.AddRouteEntries(SubRouteCollection collector, HttpConfiguration configuration, IInlineConstraintResolver constraintResolver, IDirectRouteProvider directRouteProvider)
at System.Web.Http.Routing.AttributeRoutingMapper.<>c__DisplayClass2.<>c__DisplayClass4.<MapAttributeRoutes>b__1()
at System.Web.Http.Routing.RouteCollectionRoute.EnsureInitialized(Func`1 initializer)
at System.Web.Http.Routing.AttributeRoutingMapper.<>c__DisplayClass2.<MapAttributeRoutes>b__0(HttpConfiguration config)
at System.Web.Http.CorsHttpConfigurationExtensions.<>c__DisplayClass3.<AddCorsMessageHandler>b__0(HttpConfiguration config)
at System.Web.Http.HttpConfiguration.ApplyControllerSettings(HttpControllerSettings settings, HttpConfiguration configuration)
at System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type)
at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.InitializeControllerInfoCache()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.GetControllerMapping()
at System.Web.Http.Routing.AttributeRoutingMapper.AddRouteEntries(SubRouteCollection collector, HttpConfiguration configuration, IInlineConstraintResolver constraintResolver, IDirectRouteProvider directRouteProvider)
at System.Web.Http.Routing.AttributeRoutingMapper.<>c__DisplayClass2.<>c__DisplayClass4.<MapAttributeRoutes>b__1()
at System.Web.Http.Routing.RouteCollectionRoute.EnsureInitialized(Func`1 initializer)
at System.Web.Http.Routing.AttributeRoutingMapper.<>c__DisplayClass2.<MapAttributeRoutes>b__0(HttpConfiguration config)
at System.Web.Http.CorsHttpConfigurationExtensions.<>c__DisplayClass3.<AddCorsMessageHandler>b__0(HttpConfiguration config)
at System.Web.Http.HttpConfiguration.ApplyControllerSettings(HttpControllerSettings settings, HttpConfiguration configuration)
at System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type)
at Sitecore.Services.Infrastructure.Web.Http.Dispatcher.NamespaceHttpControllerSelector.InitializeControllerDictionary()
at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
at System.Lazy`1.get_Value()
at Sitecore.Services.Infrastructure.Web.Http.Dispatcher.NamespaceHttpControllerSelector.SelectController(HttpRequestMessage request)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"

路由在global.asax.cs中注册:

protected void Application_Start(object sender, EventArgs e)
{
GlobalConfiguration.Configure(config =>
{
config.MapHttpAttributeRoutes();

//config.Routes.MapHttpRoute(
// name: "DefaultApi",
// routeTemplate: "api/{controller}/{id}",
// defaults: new { id = RouteParameter.Optional }
//);
});
SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
}

最佳答案

This solution尝试升级时为我们工作。您应该完整阅读这篇文章以了解它在做什么,但简而言之,您需要创建一个自定义 HttpControllerSelector,并在 Sitecore 添加所有路由后将其与 Sitecore 交换。注:本摘要均非我原创。我从链接的文章中收集了所有这些内容。

顺便说一句,我强烈建议避免就地升级到 Sitecore 8。我想说,使用全新安装的 Sitecore 8 然后通过包迁移内容几乎总是更好的选择。 This blog很好地了解了这两个选项。

关于sitecore - 升级到 sitecore 8 后,WEB API 调用出现 500 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32035576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com