Header Ads

Check whether iis is running or not using c# and asp.net

The below code snippet can be used to check whether IIS is running or not using c# and asp.net.
IIS_C#_asp.net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ServiceProcess;

public partial class IIS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
            bool iis = IsIISRunning();
            Response.Write(iis);
    }
    private static bool IsIISRunning()
        {
            bool iisRunning = false;

            ServiceController controller = new ServiceController("W3SVC");

            if (controller.Status == ServiceControllerStatus.Running)
            {
                iisRunning = true;
            }

            return iisRunning;
        }

    }

No comments:

Powered by Blogger.