Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net vnext api working on localhost, returns 404 on azure

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

On localhost, everything is working. If I deploy to an azure website, only MVC part is working

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 works fine, but if I go to http://myproject.azurewebsites.net/api/Messages it returns 404

like image 816
JuChom Avatar asked Feb 05 '15 17:02

JuChom


1 Answers

Here is how I solved the issue:

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

I have no clue, why it was working locally...

like image 125
JuChom Avatar answered Oct 14 '22 09:10

JuChom