简体   繁体   English

从IIS中的网站重新启动和监视服务

[英]Restart and monitor service from Website in IIS

I have a console application that monitors a folder for imports and parses them. 我有一个控制台应用程序,它监视文件夹中的导入并对其进行解析。 I want to convert this to a Windows Service. 我想将其转换为Windows服务。 What I'm not sure how to do or if it's possible is have an IIS hosted website be able to show the status of that service and manually restart it if necessary. 我不确定该怎么办,或者是否有可能让IIS托管的网站能够显示该服务的状态,并在必要时手动重新启动它。 The website and the windows service would be running on the same server. 该网站和Windows服务将在同一服务器上运行。

Yes, you can create a website that checks for the status and restarts the Windows Service by using the ServiceController class. 是的,您可以创建一个网站来检查状态并使用ServiceController类重新启动Windows服务。 You can refer to this answer (or even the official documentation ) for sample code on both checking the status and restarting the service. 您可以参考该答案 (甚至是官方文档 )以获取有关检查状态和重新启动服务的示例代码。

Just keep in mind that the website will have to run (under IIS settings) with a user identity that has enough privileges (normally administrator) on the server. 只需记住,该网站将必须使用在服务器上具有足够特权(通常是管理员)的用户身份运行(在IIS设置下)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM