ASP.Net vnext api runs on localhost, returns 404 on blue

I created a very small project with ASP.NET vnext with a simple MVC controller and a simple Api controller.

Everything works on the local host. If I turn around on the azure site, only part of the MVC works

Here is my project.json

{ "webroot": "wwwroot", "version": "1.0.0-*", "exclude": [ "wwwroot" ], "packExclude": [ "node_modules", "bower_components", "**.kproj", "**.user", "**.vspscc" ], "dependencies": { "Microsoft.AspNet.Server.IIS": "1.0.0-beta2", "Microsoft.AspNet.Mvc": "6.0.0-beta2" }, "frameworks" : { "aspnet50" : { }, "aspnetcore50" : { } } } 

Startup.cs

 using Microsoft.AspNet.Builder; using Microsoft.Framework.DependencyInjection; namespace Project.Web6 { public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddMvc(); } public void Configure(IApplicationBuilder app) { // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 app.UseMvc(); } } } 

MVC controller

 public class HomeController : Controller { // GET: /<controller>/ public string Index() { return "Hello world"; } } 

API controller

 [Route("api/[controller]")] public class MessagesController : Controller { // GET: api/values [HttpGet] public IEnumerable<string> Get() { return new string[] { "value1", "value2" }; } } 

The MVC controller is working fine, but if I go to http://myproject.azurewebsites.net/api/Messages , it will return 404

+6
source share
1 answer

This is how I solved the problem:

 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action}/{id?}", defaults: new { controller = "Home", action = "Index" }); }); 

I have no clue why it worked locally ...

+2
source

Source: https://habr.com/ru/post/982058/


All Articles