I am trying to use MVC controller and WebAPI controller in one project, but I got 404 errors for webapi. I started the project as MVC Project in vs 2015, but then added a webapi control, and with the default code it throws a 404 error
what could be a possible solution. I tried some solution on Stackoverflow, but they did not work, one of them is below the link (Accepted there). All ASP.NET Web API controllers return 404
Global.ASAX File Code:
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register);
WEBAPI.CONFIG FILE
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 } ); } }
Route Configuration File Code
public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } }
WebAPI Controller Code
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; using O365_APIs_Start_ASPNET_MVC.Models; using Microsoft.IdentityModel.Clients.ActiveDirectory; using O365_APIs_Start_ASPNET_MVC.Helpers; using System.Threading.Tasks; namespace O365_APIs_Start_ASPNET_MVC.Controllers { public class MAILAPIController : ApiController { private MailOperations _mailOperations = new MailOperations();
ALSO GETTING A NUGET RECOVERY ERROR IN THE SAME SOLUTION Nuget failed to repair PNG
user3177519
source share