首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >确保HttpConfiguration.EnsureInitialized()

确保HttpConfiguration.EnsureInitialized()
EN

Stack Overflow用户
提问于 2013-11-14 03:52:26
回答 16查看 83.7K关注 0票数 155

我已经安装了Visual 2013,当我运行我的应用程序时,我会看到下面的错误。

我不知道要在哪里初始化这个对象。

该怎么办呢?

代码语言:javascript
复制
    Server Error in '/' Application.

The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[InvalidOperationException: The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.]
   System.Web.Http.Routing.RouteCollectionRoute.get_SubRoutes() +101
   System.Web.Http.Routing.RouteCollectionRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request) +63
   System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext) +107
   System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext) +233
   System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +60
   System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +82
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408

这是给AlumCloud

EN

回答 16

Stack Overflow用户

回答已采纳

发布于 2013-11-14 06:07:53

现在,请参阅@龙胆的答案如下以正确的方式处理此问题。

Application_Start方法末尾的Global.Asax.cs中,尝试添加:-

代码语言:javascript
复制
GlobalConfiguration.Configuration.EnsureInitialized(); 
票数 149
EN

Stack Overflow用户

发布于 2014-01-04 22:26:17

如果您在Application_Start的末尾执行此操作,将为时已晚,因为WebApiConfig.Register已经被调用。

解决这一问题的最佳方法是使用新的初始化方法,在Global.asax中替换:

代码语言:javascript
复制
WebApiConfig.Register(GlobalConfiguration.Configuration);

通过

代码语言:javascript
复制
GlobalConfiguration.Configure(WebApiConfig.Register);
票数 249
EN

Stack Overflow用户

发布于 2015-01-21 11:13:08

实际上,当我在我的WebApi中使用属性路由时,我得到了这个错误。

我有

路线(“webapi/siteTypes/{siteTypeId”)

而不是

路由(“webapi/siteTypes/{siteTypeId}”)

我的路线,并得到了这个错误。我只是错过了即将结束的卷曲括号。一旦我把它加回去,这个错误就不会再发生了。

票数 80
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19969228

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档