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 /y

It will stop the IIS Admin Service and all other relevant services. Now, run this command:

net start w3svc

It 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:inetpubwwwrootAspNetCore46

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

Step 3: Create a New Application Pool in IIS

Create a new IIS application pool under the .NET CLR version of “No Managed Code.” Then create your new IIS app under your current IIS site. You can also create a new IIS site. Then point it to the folder that contains the files of your publish output.

Step 4: Load your application

In this step, your application should work perfectly. But if it doesn’t happen, open your web.config file and specify the process for IIS initiating ASP.NET Core. Also, activate out logging by setting stdoutLogEnabled to true. It will allow you to the logs, identify the issue and create a solution.

Conclusion

In this article, you have learnt the detailed way for configuring, installing and deploying ASP.NET Core to IIS. By using the extensible web server to the ASP.NET Core hosting, you can enjoy an extra level of configurability and security.

Check out these top 3 WordPress hosting services:

0

Was this article helpful?

Submit

Be the first to comment

Leave a Reply

Your email address will not be published.


*