Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

asp.net-core

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).

like image 846
selva Avatar asked May 18 '15 08:05

selva


People also ask

How do I run .NET Core without IIS?

It is easy to run your asp.net web application without installing any web server. For running your application without IIS you have to use Cassini Desktop Adapter. Now your application is running without IIS It also support VWG application.

Can we run an ASP.NET Core application without using the built in Kestrel web server?

Yes, you could use WebListener web server instead of Kestrel. WebListener only works on the Windows platform but since that is where you are running, it's an option for you.

What is self hosting in .NET Core?

Self Host just means it uses the built-in Web Server, which is in contrast to classic ASP.NET Framework Web Apps which typically requires IIS or the built-in WebDev server to run.

What is difference between self hosting and IIS hosting?

Hosting a Web API inside IIS is quite straightforward as the process is identical to hosting a web application. On the other hand, hosting a Web API in it's own process requires the creation of a host application and is referred as self-hosting.


2 Answers

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();     } } 
like image 101
Shaun Luttin Avatar answered Sep 21 '22 17:09

Shaun Luttin


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.

like image 28
chen Avatar answered Sep 20 '22 17:09

chen