csharp Web Application Self Check

protected int SelfCheck()
{
	try
	{
		//build up Url to homepage, specific to this Application
		Uri uri = new Uri("http://" + Request.ServerVariables["LOCAL_ADDR"] + ":" + Request.ServerVariables["SERVER_PORT"] + "/default.aspx");

		//setup request
		HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
		request.Method = WebRequestMethods.Http.Head;
		request.Timeout = 10000;//1000ms = 1 second

		//get response code
		HttpWebResponse response = (HttpWebResponse)request.GetResponse();
		return response.StatusCode;
	}
	catch
	{
		return 500;//error, default to 500
	}
}
Performs a Head request to itself and returns the HTTP Status Code.

Updated: Thursday 19th May 2011, 01:28am

There are 0 comments

Leave a comment of your own

Comments are currently closed.