Check Server Status Using C#.Net
A SMALL NOTE FROM EDITOR:
Hi all, This is my 200th Post. All this Journey started with a single Post in a small newbie blog @ October,2012 which has evolved into this massive asp.net Repository as of today. This site has crossed more than 0.2 Millions Pageviews from 160 Countries which itself speaks of its Popularity . I would heartily thank all the readers of this site and request you to be the part of this site in the future as well. New Ideas and Innovative thoughts are always welcomed. You can contact me Personally at my mail Id vishalranjan2k11@gmail.com.
In this Post We can see check how to check the status of the Server Using C#.Net. Its a kind of Ping Request to the Target server to check its Status. Refer the Code Snippet Below:
Design Part:
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Check Server Status</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> <br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br /> <br /> <asp:Label ID="lblMsg" runat="server" ForeColor="Red"></asp:Label> </div> </form> </body> </html>
Code-Behind:
using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Net.NetworkInformation; public partial class CheckServerStatus : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected string PingSvrs(string hostname) { string functionReturnValue = null; long rtTime = 0; Ping ping = new Ping(); try { PingReply reply = ping.Send(hostname); if (reply.Status == IPStatus.Success) { functionReturnValue = "G:Response Received"; rtTime = reply.RoundtripTime; } else { functionReturnValue = "R:" + hostname + " Status: " + reply.Status.ToString(); } } catch (Exception ex) { functionReturnValue = "R:" + hostname + " error: " + ex.Message; } return functionReturnValue; } protected void Button1_Click(object sender, EventArgs e) { lblMsg.Text = PingSvrs(TextBox1.Text); } }
No comments:
Post a Comment
Thank You for Your Comments. We will get back to you soon.