2015-02-05 11 views
6

Ich habe ein sehr kleines Projekt mit ASP.NET vnext mit einem einfachen MVC-Controller und einem einfachen Api-Controller erstellt.ASP.Net vnext API funktioniert auf localhost, gibt 404 auf azurblau

Auf localhost funktioniert alles. Wenn ich auf eine azur Website bereitstellen, nur einen Teil MVC

hier arbeitet, ist mein 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" }; 
    } 
} 

Die MVC-Controller funktionieren gut, aber wenn ich zu http://myproject.azurewebsites.net/api/Messages gehen gibt sie 404

+0

Was und wie hast du dich auf azur gemacht? –

+0

wenn dieser Link hilft: https://github.com/aspnet/Home/wiki/Deploy-an-AspNet-vNext-application-to-Microsoft-Azure-websites sagen Sie mir, es als Antwort zu posten :) – astaykov

Antwort

2

Hier ist, wie ich das Problem gelöst:

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

Ich habe keine Ahnung, warum es vor Ort zu arbeiten. ..

Verwandte Themen