Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Check Whether IIS Running or Not in C#, VB.Net using Asp.net

Feb 9, 2015
Introduction

Here I will explain how to check whether IIS manger running or not in
c#, vb.net using asp.net. We can check whether IIS manager running or not using ServiceController in c#, vb.net using asp.net.

Description:
  
In previous articles I explained
install iis manger in windows, IIS cannot open w3svc service on computer, host website in IIS with custom url in asp.net, get values from ienumerable list in c#, vb.net, convert datatable to generic list using LINQ and many articles relating to asp.net, c#, vb.net, jQuery and JavaScript and. Now I will explain how to check whether IIS manager running or not in c#, vb.net using asp.net.

If you want to check IIS running or not we need to write the code like as shown below

C# Code


protected void btnClick_Click(object sender, EventArgs e)
{
ServiceController controller = new ServiceController("W3SVC");
lblStatus.Text = controller.Status.ToString();
}
VB.NET Code


Protected Sub btnClick_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim controller As New ServiceController("W3SVC")
lblStatus.Text = controller.Status.ToString()
End Sub
If you want to see it in complete example open your Default.aspx page and write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Check IIS Running Status in Asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnClick" runat="server" Text="Check Status"
onclick="btnClick_Click" />
<asp:Label ID="lblStatus" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
Now we need to add System.ServiceProcess reference to our application for that right click on your application à select Add Reference à select System.ServiceProcess like as shown below


Now open your code behind file and add following namespaces

C# Code


using System;
using System.ServiceProcess;
VB.NET Code


Imports System.ServiceProcess
Now write the following code in code behind to check the status of IIS manager

C# Code

protected void btnClick_Click(object sender, EventArgs e)
{
ServiceController controller = new ServiceController("W3SVC");
lblStatus.Text = controller.Status.ToString();
}
VB.NET Code


Imports System.ServiceProcess
Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Protected Sub btnClick_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim controller As New ServiceController("W3SVC")
lblStatus.Text = controller.Status.ToString()
End Sub
End Class
Demo


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

2 comments :

Unknown said...

Hi Sir,
Good article and very helpful, by this i can find out idle time of application cause many time application stop work after some time idle state.

Bansi Kaneriya said...

Hi Sir,
Good article and very helpful, by this i can find out idle time of application cause many time application stop work after some time idle state.

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.