MVC6 (.Net core) applications are self hosted : Optional IIS integration

All ASP.NET Core applications are self-hosted.

Yes you read it right!

So does it mean IIS is not required?

Yes, I mean we can host MVC6 application even without IIS.

Wow…but How?

I assume you have already downloaded .Net core from here.

Next step would be to create sample MVC6 project.

For now you can directly clone it from Github by below commands:

git clone https://github.com/NeelBhatt/cli-samples.git
cd cli-samples\HelloMvc

Then we would restore and run the project as below:

dotnet restore
dotnet run 

That is it!

Now navigate to localhost:5000 in your web browser and you can see your application hosted there.

You must be wondering how it happened?

You can check it by yourself in code.

Open Program.cs class and you can see below code there:

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() //// Here IIS integration is optional
            .UseStartup()
            .Build();

        host.Run();
    }
}

As you can see in above comments, IIS integration is optional in .Net core.

Happy coding!

Advertisement

4 thoughts on “MVC6 (.Net core) applications are self hosted : Optional IIS integration

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s