How to Configure, Install and Deploy ASP.NET Core to IIS
ASP.NET Core is a free and a composable framework for building web apps. It is open source and completely free. You can get it on Github. The modular framework performs significantly better than ASP.NET. In this article, you will find the complete guide for configuring, installing and deploying it to IIS.
Configuring Your ASP.NET Core App for IIS
When you create a new ASP.NET Core, you will see a Program.cs file, which has the following codes:publicclassProgram
{
publicstaticvoidMain(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup()
.Build();
host.Run();
}
}
Here, WebHostBuilderis configuring and creating WebHost, which is basically an object that functions as the application and the web server. UseKestrel() is registering the IServer interface for Kestrel, which is a cross-platform web server. Here, IServer will work as a host for your app. By including UseIISIntegration(), you are using IIS as a reverse proxy in front of Kestrel.
Creating an ASP.NET Core project also results in the creation of a web.config file. It looks like this:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/> </handlers> <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".logsstdout" forwardWindowsAuthToken="false"/> </system.webServer> </configuration>Basically, it registers AspNetCoreModule, which deals with all the incoming traffic to IIS, as an HTTP handler. It also works as a reverse proxy server. But more importantly, AspNetCoreModule is responsible for running your web app successfully.
Installing .NET Core Windows Server Hosting Bundle
You can download .NET Core Windows Server from here. You need to install it before deploying your web app. At the same time, .NET Core runtime, libraries and ASP.NET Core module will also be installed. Then you might have to run the following command in the command prompt:net stop was /yIt will stop the IIS Admin Service and all other relevant services. Now, run this command:
net start w3svcIt will force the IIS services to re-read the registry. As a result, all the changes will be picked up for the extensible web server.
Deploying ASP.NET Core to IISStep 1: Pick a Publish TargetStep 2: Copy Your Publish Output to Your Preferred Location
Now, you have to copy the files to your desired location. In our case, we are copying them right here:C:inetpubwwwrootAspNetCore46If you are deploying to a local dev box, you have the option of copying the files locally. But in case of the remote server, you should compress them and then move to the server.