Introduction:
Here I will explain how to start or stop IIS service in c#, vb.net using asp.net. We can start or stop IIS service using ServiceController in c#, vb.net using asp.net.
Description:
In previous articles I explained check whether IIS service running or not in c#, vb.net, install iis manger in windows, IIS cannot open w3svc service on computer, host website in IIS with custom url in asp.net and many articles relating to asp.net, c#, vb.net, jQuery and JavaScript and. Now I will how to start or stop IIS service in c#, vb.net using asp.net.
In previous articles I explained check whether IIS service running or not in c#, vb.net, install iis manger in windows, IIS cannot open w3svc service on computer, host website in IIS with custom url in asp.net and many articles relating to asp.net, c#, vb.net, jQuery and JavaScript and. Now I will how to start or stop IIS service in c#, vb.net using asp.net.
If you want to start or stop IIS
service in c#,
vb.net
using asp.net
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");
if (controller.Status == ServiceControllerStatus.Running)
controller.Stop();
else if (controller.Status == ServiceControllerStatus.Stopped)
controller.Start();
else
controller.Stop();
}
|
VB.NET
Code
Protected Sub btnClick_Click(ByVal
sender As Object,
ByVal e As EventArgs)
Dim controller As New ServiceController("W3SVC")
If controller.Status = ServiceControllerStatus.Running
Then
controller.[Stop]()
ElseIf controller.Status = ServiceControllerStatus.Stopped Then
controller.Start()
Else
controller.[Stop]()
End If
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>Start or Stop IIS
service in Asp.net</title>
</head>
<body>
<form id="form1"
runat="server">
<div>
<asp:Button ID="btnClick"
runat="server"
Text="Check
Status"
onclick="btnClick_Click" />
</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
|
VB.NET
Code
|
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. |
|||
|
|||
1 comments :
Note: Only a member of this blog may post a comment.