Skip to content

Update Host a Windows Service topic#5315

Merged
scottaddie merged 2 commits into
dotnet:masterfrom
guardrex:guardrex/windows-service-samp
Jan 31, 2018
Merged

Update Host a Windows Service topic#5315
scottaddie merged 2 commits into
dotnet:masterfrom
guardrex:guardrex/windows-service-samp

Conversation

@guardrex
Copy link
Copy Markdown
Collaborator

@guardrex guardrex commented Jan 30, 2018

Replaces #5095

Internal Review Topic

Thanks to @seprix91 for bringing this to our attention.

  • Updates samp to 2.0 and institutes tabs for 1.x coverage.
  • Tested the updated sample.
  • Relative links
  • UE updates

@guardrex guardrex changed the title [WIP] Update Host a Windows Service topic Update Host a Windows Service topic Jan 31, 2018
@guardrex guardrex removed the WIP label Jan 31, 2018
The recommended way to host an ASP.NET Core app on Windows without using IIS is to run it in a [Windows Service](/dotnet/framework/windows-services/introduction-to-windows-service-applications). When hosted as a Windows Service, the app can automatically start after reboots and crashes without requiring human intervention.

[View or download sample code](https://github.com/aspnet/Docs/tree/master/aspnetcore/host-and-deploy/windows-service/sample) ([how to download](xref:tutorials/index#how-to-download-a-sample)). See the [Next Steps](#next-steps) section for instructions on how to run it.
[View or download sample code](https://github.com/aspnet/Docs/tree/master/aspnetcore/host-and-deploy/windows-service/sample) ([how to download](xref:tutorials/index#how-to-download-a-sample)). For instrucitons on how to run the sample app, see the sample's *README.md* file.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instrucitons --> instructions

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DAH! ..... no spell check run this time obviously.

1. Test by creating and starting the service.

The `binPath` value is the path to the app's executable, including the executable filename itself.
Open an administrator command prompt window to use the [sc.exe](https://technet.microsoft.com/library/bb490995) command-line tool to create and start a service. If the service is named MyService, published to `c:\svc`, and named AspNetCoreService, the commands are:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we use "command shell" instead of "command prompt window". How about "Open a command shell with administrative privileges..."?

[!code-csharp[](windows-service/sample/WebHostServiceExtensions.cs?name=ExtensionsClass)]

## Next steps
1. In `Program.Main`, call the new extension method,`RunAsCustomService`, instead of `RunAsService`:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space before RunAsCustomService


1. 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 required `appsettings.json` file and the `wwwroot` folder with its contents.

1. Open an **administrator** command prompt.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

command prompt --> command shell

@guardrex
Copy link
Copy Markdown
Collaborator Author

Thanks @scottaddie for the quick review. Changes made. 👍

@scottaddie scottaddie merged commit ce47040 into dotnet:master Jan 31, 2018
@guardrex guardrex deleted the guardrex/windows-service-samp branch January 31, 2018 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants