c# - 检查 IIS 是否已安装并正在运行

标签 c# asp.net iis

在我们的应用程序中,我们想要确定 iis 是否安装在机器中。如果已安装,那么我们需要确定它是否正在运行。

有什么方法可以获取这些详细信息。

最佳答案

Using Managed Code to Detect if IIS is Installed and ASP/ASP.NET is Registered

IIS 是否运行检查下面的代码

只需将“System.ServiceProcess”的引用添加到您的项目。

    ServiceController sc = new ServiceController("World Wide Web Publishing Service");
if ((sc.Status.Equals(ServiceControllerStatus.Stopped) || sc.Status.Equals(ServiceControllerStatus.StopPending))) {
    Console.WriteLine("Starting the service...");
    sc.Start();
}
else {
    Console.WriteLine("Stopping the service...");
    sc.Stop();
}

关于c# - 检查 IIS 是否已安装并正在运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9816751/

相关文章:

c# - 具有完整 IIS 的 Azure 模拟器

c# - 在启动时验证 WCF 服务

c# - 比较 byte[] 和 T

c# - 确定 Kubernetes 中应用程序关闭的原因

c# - 如何在 C# 中生成唯一的文件名

c# - 客户端 nit 中的列表框更改出现在服务器端,asp 向导无法正常工作

asp.net - 想要在 ASP.NET web 应用程序中使用 index.aspx 而不是 default.aspx

c# - 无法加载文件或程序集 'System.Web, Version=4.0.0.0, Culture=neutral' 或其依赖项之一。访问被拒绝

c# - BlobContainerClient - 获取根目录中的所有 blob

c# - 使用 C#.Net 通过 FTPS (SSL/TLS) 传输文件