Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue in Global.asax.cs page in MVC4

I my ASP.NET MVC 4 Project, my Global.asax.cs page shows the error on

 WebApiConfig.Register(GlobalConfiguration.Configuration); 

The name 'GlobalConfiguration' does not exist in the current context

I have done many controllers and Views and all... How can I solve this issue and recover my project?

Here is the rest of my code for context

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);         }     } } 
like image 263
neel Avatar asked Jan 28 '14 09:01

neel


People also ask

How do I add global asax Cs to my website?

How to add global. asax file: Select Website >>Add New Item (or Project >> Add New Item if you're using the Visual Studio web project model) and choose the Global Application Class template. After you have added the global.

What is global asax Cs in MVC?

The Global. asax file is a special file that contains event handlers for ASP.NET application lifecycle events. The route table is created during the Application Start event. The file in Listing 1 contains the default Global. asax file for an ASP.NET MVC application.

When should I use global asax?

Global. asax is an optional file which is used to handling higher level application events such as Application_Start, Application_End, Session_Start, Session_End etc. It is also popularly known as ASP.NET Application File. This file resides in the root directory of an ASP.

What is Application_Start in global asax?

Application_Start. The Application_Start event is fired the first time when an application starts. Session_Start. The Session_Start event is fired the first time when a user's session is started. This typically contains for session initialization logic code.


1 Answers

Make sure you have assembly System.Web.Http.WebHost.dll referenced. This is where GlobalConfiguration is.

like image 95
David Bohunek Avatar answered Sep 20 '22 06:09

David Bohunek