提问者:小点点

MVC4中global.asax.cs页面中的问题


在我的ASP.NET MVC 4项目中,我的页显示了错误

 WebApiConfig.Register(GlobalConfiguration.Configuration);

名称“globalConfiguration”在当前上下文中不存在

我做了许多控制器和视图和所有。。。如何解决此问题并恢复项目?

下面是我的上下文代码的其余部分

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;

namespace .....
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
    }
}

共3个答案

匿名用户

确保引用了程序集。这就是GlobalConfiguration的位置。

匿名用户

对于。NET Framework 4.5.1,GlobalConfiguration位于:

PM> Install-Package Microsoft.AspNet.WebApi.WebHost

匿名用户

null

上面的命令重新安装所有依赖项,并且通常在我遇到nuget包引用问题时执行这个技巧。