X

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.

Liked this post? Empower your friends by sharing it!
Categories: ASP.NET IIS

View Comments (7)

  • " 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

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

  • 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

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

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

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

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

Related Post