Is it possible to self-host an ASP.NET Core Application without IIS?

asp.net Core

asp.net Core Problem Overview


I have a full-working ASP.NET MVC application (.NET Core, ASP.NET Core) which runs fine in Visual Studio (which uses IISExpress).

I would now like to have a console application which takes the ASP.NET Core application and hosts it (self hosting).

asp.net Core Solutions


Solution 1 - asp.net Core

> Is it possible to self-host an ASP.NET Core Application without IIS?

Yes. In fact, all ASP.NET Core applications are self-hosted. Even in production, IIS/Nginx/Apache are a reverse proxy for the self-hosted application.

In a reasonably standard Program.cs class, you can see the self-hosting. The IISIntegration is optional - it's only necessary if you want to integrate with IIS.

public class Program
{
    public static void Main(string[] args)
    {
        var config = new ConfigurationBuilder()
            .AddCommandLine(args)
            .AddEnvironmentVariables(prefix: "ASPNETCORE_")
            .Build();

        var host = new WebHostBuilder()
            .UseConfiguration(config)
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();

        host.Run();
    }
}

Solution 2 - asp.net Core

Yes,ASP.NET Core supports the Open Web Interface for .NET (OWIN),your have two options to host your Asp.net core web application:

  1. IIS

  2. Self-Host

>But,self-hosting web application can't restart automatically on system boot and restart or in the event of a failure.

Solution 3 - asp.net Core

YES > ASP.NET 5 is completely decoupled from the web server environment that hosts the application. ASP.NET 5 supports hosting in IIS and IIS Express, and self-hosting scenarios using the Kestrel and WebListener HTTP servers. Additionally, developers and third party software vendors can create custom servers to host their ASP.NET 5 apps.

more info: ASP.NET documentation - Servers

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionselvaView Question on Stackoverflow
Solution 1 - asp.net CoreShaun LuttinView Answer on Stackoverflow
Solution 2 - asp.net CorechenView Answer on Stackoverflow
Solution 3 - asp.net CoreSorenView Answer on Stackoverflow