Run asp.net core web app as a windows service via IIS

You are looking at revision 4 of this page, which may be out of date. View the latest version.  

Rick Strahl has a thorough article on publishing your dot net core app with IIS

This requires you to install the AspNetCoreModule into IIS and it is this module which manages the lifetime of your dot net core process which runs separately to w3wp.exe in its own process (e.g. WebApplication1.exe)

This is less than ideal if your web app runs background tasks that you want running constantly - it requires you to poll your website after a server or IIS reboot to ensure your process is loaded and running (via AspNetCoreModule)

It is possible to host the dotnet core app as a windows service but this wont work with AspNetCoreModule - the latter will simply ignore the running process and start its own new instance.

To get this working so you have your dotnet core app running as a service and have it hosted via IIS (importantly on ports 80,443 with other hosted web apps) the following steps are required: (assumes you are starting from a File -> New Project -> ASP.NET Core Web Application

1) in project.json add references to

"Microsoft.AspNetCore.Hosting": "1.0.0-*",
"Microsoft.AspNetCore.Hosting.WindowsServices": "1.0.0-*",

This will result in an error

The dependency Microsoft.AspNetCore.Hosting.WindowsServices 1.0.0 does not support framework .NETCoreApp,Version=v1.0.

You need to target the full framework - this suited my purposes fine as i was running on windows only and depended on libraries not yet supported by dotnet core. If you absoutely must have this working on other platforms as a pure dotnet core app then check out dasMulli/dotnet-win32-service

Posted by: Wallace Turner
Last revised: 08 Mar, 2017 07:07 AM History
You are looking at revision 4 of this page, which may be out of date. View the latest version.

Comments

No comments yet. Be the first!

No new comments are allowed on this post.