Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebApiConfig does not exist in current context

I'm using asp.net mvc 5.I'm doing the following tutorial, http://venkatbaggu.com/signalr-database-update-notifications-asp-net-mvc-usiing-sql-dependency/

but in the Global.sax file it says that "WebApiConfig does not exist in current context".why is that?

here are some codes

protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        GlobalConfiguration.Configure(WebApiConfig.Register); //this is where error shows
        //Start SqlDependency with application initialization
        SqlDependency.Start(connString);
    }
like image 642
Thilina De Silva Avatar asked Mar 24 '15 09:03

Thilina De Silva


2 Answers

Do you have a WebApiConfig.cs file in your App_Start folder? If you take a look at the source that the tutorial references in github then the WebApiConfig file is as follows:

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

namespace SignalRDbUpdates
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
}

Take a look at the App_Start folder on the github repository: https://github.com/venkatbaggu/signalrdatabasenotifications/tree/master/SignalRDbUpdates/App_Start

like image 58
F Chopin Avatar answered Sep 19 '22 03:09

F Chopin


For me, I had moved the code folder, and for some reason the

WebApiConfig.cs
AuthConfig.cs
Filter.cs
BundleConfig.cs

had been excluded from the project, reincluded them and it worked again. Because the folder wasn't expanded I never realised that they had been excluded.

like image 27
kolin Avatar answered Sep 20 '22 03:09

kolin