3
最近,我們從Sitecore 7.5升級到Sitecore 8.0。升級後,自定義Web API調用開始返回與下面的異常500個錯誤代碼:升級到sitecore後WEB API調用出現500錯誤8
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"));
}
最好在答案中提供解決方案的摘要,請參閱[是否只包含其他鏈接的答案,真的是「好答案」?](http://meta.stackexchange.com/questions/8231/ are-answers-that-just-contain-links-elsewhere-really-good-answers) – Liam
我向兩個鏈接提供了上下文。另外,我不會剽竊或竊取別人的工作。我們用這篇確切的文章來解決我們的問題,我不打算把它粘貼在這裏。 – Casey
這工作對我來說,但我需要添加以下內容:'公共覆蓋IDictionary <字符串,HttpControllerDescriptor> GetControllerMapping() { return _controllers; }'到'CustomHttpControllerSelector' –