1

Can a console app host both an asp.net mvc website and asp.net web api? At the moment following boiler plate code hosts only web api. Need to figure out how to add MVC website to it.

class Program
{
    static void Main(string[] args)
    {
            using (WebApp.Start<Startup>("http://localhost:8080"))
            {
                Console.Write("Server Running. Press any key to exit.."); Console.ReadKey();
            }
    }
}
public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        var config = new HttpConfiguration();
        config.Routes.MapHttpRoute(name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );
        app.UseWebApi(config);
    }
}
Ravi J
  • 61
  • 1
  • 4
  • Thanks, but no, that link only hosts web api, not asp.net mvc. – Ravi J Jan 30 '16 at 13:10
  • The link also points out the correct answer, which is that there is no built-in way to self-host MVC 5 and gives 2 possible alternatives (NancyFx or MVC Core). I don't see how your question differs from that one in any significant way that can be answered differently. – NightOwl888 Jan 30 '16 at 17:30

1 Answers1

0

Contrary to ASP.NET Web API, the current stable version of ASP.NET MVC (5.0) cannot be self hosted outside of IIS. This will be possible with the upcoming ASP.NET Core 1.0:

To be clear, ASP.NET 4.6 is the more mature platform. It's battle-tested and released and available today. ASP.NET Core 1.0 is a 1.0 release that includes Web API and MVC but doesn't yet have SignalR or Web Pages. It doesn't yet support VB or F#. It will have these subsystems some day but not today.

We don't want anyone to think that ASP.NET Core 1.0 is the finish line. It's a new beginning and a fork in the road, but ASP.NET 4.6 continues on, released and fully supported. There's lots of great stuff coming, stay tuned!

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928