Reputation: 391
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);
}
Upvotes: 8
Views: 19518
Reputation: 2344
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.
Upvotes: 1
Reputation: 2786
It's not clear when you get this error, at compile time or when debugging?
If it happens during compilation then check if WebApiConfig.cs
file exists.
If it's happening when you debugging, then you need to check if you made some changes in this file, because default implementation should work without a problem.
Maybe the problem is with next line?
SqlDependency.Start(connString);
Check if connections string is correct.
EDIT: I tried to download and run the project and first I got this error:
Entering break mode failed for the following reason: Source file 'e:\BlogDemos\SignalRDbUpdates\SignalRDbUpdates\Global.asax.cs' does not belong to the project being debugged
Which is strange, because I don't have "E" drive at all. But after changing Managaed Pipilene Mode
to Classic
and back to Integrated
(default value) and building the project it started to work correctly.
Upvotes: 0
Reputation: 728
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
Upvotes: 22