Running ASP.NET Core applications on IIS

Preparing for CodeCamp Cluj 2016 I needed to host one ASP.NET Core application on IIS web server. I had one simple box with clean IIS available in my network and I installed my ASP.NET Core application on it. This blog post is simple step by step guide showing how to prepare and configure IIS for ASP.NET Core applications.

I started with knowledge that when publishing ASP.NET Core application to Azure then all the work is done for me and I have nothing additional to do. I also know that for IIS reverse proxy is used to communicate with Kestrel. So, I expected at least some work with vanilla IIS. But it was all easier than I thought.

Configuring IIS and publishing ASP.NET Core application

  1. Create new host on IIS and make sure it is accessible.

  2. Download and install .NET Core Windows Server Hosting package.

  3. Run the following commands on elevated command prompt:
    net stop was /y
    net start w3svc

  4. Change basic settings of application pool and set .NET Framework version (or .NET CLR version) to “No managed code”.

  5. Make sure that Program.cs file of ASP.NET Core application looks similar to this:

    public class Program
    {
       
    public static void Main(string
    [] args)
        {
           
    var host = new WebHostBuilder
    ()
                .UseKestrel()
                .UseContentRoot(
    Directory
    .GetCurrentDirectory())
                .UseIISIntegration()
    // IMPORTANT!!!
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }
    }

  6. Publish application to some folder and move published files to IIS host folder using copy and paste.

It was all I had to do to make my ASP.NET Core application run on IIS. I used simple and primitive copy-paste deployment over Remote Desktop to get published files from local folder to IIS web host folder.

For more information and troubleshooting tips there is official page Publishing to IIS available.

Gunnar Peipman

Gunnar Peipman is ASP.NET, Azure and SharePoint fan, Estonian Microsoft user group leader, blogger, conference speaker, teacher, and tech maniac. Since 2008 he is Microsoft MVP specialized on ASP.NET.

    8 thoughts on “Running ASP.NET Core applications on IIS

    • November 16, 2016 at 11:20 am
      Permalink

      ” 6. Publish application to some folder and move published files to IIS host folder using copy and paste. ” <- and that part IMHO is step back from WebDeploy

    • November 16, 2016 at 11:38 am
      Permalink

      Adam, you can use WebDeploy too and everything Visual Studio can offer for web applications publishing. In my case WebDeploy would have been total overkill as I publish small application once per week.

    • November 16, 2016 at 4:30 pm
      Permalink

      Can you give some more details about subsequent deployments. The first one is always the easiest.

      Is it better to stop the IIS Service before copying the files over to the IIS host folder?

      I’ve had issues where the files are being used by another process and it does not let me copy the files over.

      Can we only copy over only the changed files or should we replace all the files? My entire deployment folder can be quite big to FTP to the server every single time.

      Thanks

    • November 17, 2016 at 8:02 am
      Permalink

      If you want stable and reliable deployment mechanism then please go with WebDeploy. Copy and paste (and stopping IIS) is not an option for boxes in real use.

    • Pingback:Szumma #067 – 2016 47. hét | d/fuel

    • February 9, 2018 at 12:36 pm
      Permalink

      Very helpful and Great information,
      I appreciate advise especially coming from a professional.
      Thanks again and keep up the great work!

    • February 22, 2018 at 9:50 am
      Permalink

      Hello Gunnar,
      I like to know more about the hosting in an ASP.NET Core, is it different as compare to ASP.NET ?

    • February 22, 2018 at 9:52 am
      Permalink

      Not much on configuring level but internally it is different. ASP.NET Core uses internal web server (Kestrel) and when run on IIS then IIS is working like a proxy between user and Kestrel. Same goes for Linux.

    Leave a Reply

    Your email address will not be published. Required fields are marked *