ce47040e91
* Update Host a Windows Service topic Update Updates * React to feedback |
||
---|---|---|
.. | ||
Controllers | ||
Views | ||
wwwroot | ||
.bowerrc | ||
AspNetCoreService.csproj | ||
CustomWebHostService.cs | ||
Program.cs | ||
README.md | ||
Startup.cs | ||
WebHostServiceExtensions.cs | ||
app.config | ||
appsettings.Development.json | ||
appsettings.json | ||
bower.json | ||
bundleconfig.json | ||
newfile2.txt |
README.md
Custom WebHost Service Sample
This sample shows the recommended way to host an ASP.NET Core app on Windows without using IIS as a Windows Service. This sample demonstrates the features described in Host an ASP.NET Core app in a Windows Service.
Instructions
The sample app is a simple MVC web app modified according to the instructions in Host an ASP.NET Core app in a Windows Service.
To run the app in a service, perform the following steps:
-
Create a folder at c:\svc.
-
Publish the app to the folder with
dotnet publish --configuration Release --output c:\\svc
. The command will move the app's assets to the folder, including the requiredappsettings.json
file and thewwwroot
folder with its contents. -
Open an administrator command shell.
-
Execute the following commands:
sc create MyService binPath="c:\svc\aspnetcoreservice.exe" sc start MyService
-
In a browser, go to
http://localhost:5000
to verify that the service is running. -
To stop the service, use the command:
sc stop MyService
If the app doesn't start up as expected when running in a service, a quick way to make error messages accessible is to add a logging provider, such as the Windows EventLog provider. Another option is to check the Application Event Log using the Event Viewer on the system. For example, here's an unhandled exception for a FileNotFound error in the Application Event Log:
Application: AspNetCoreService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean)
at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(System.Collections.Generic.IList`1<Microsoft.Extensions.Configuration.IConfigurationProvider>)
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
...