{"id":2281,"date":"2012-10-24T13:01:10","date_gmt":"2012-10-24T17:01:10","guid":{"rendered":"http:\/\/www.iowawebnet.com\/ein\/?p=2281"},"modified":"2012-10-22T13:12:11","modified_gmt":"2012-10-22T17:12:11","slug":"website-uptime-monitor","status":"publish","type":"post","link":"https:\/\/www.iowawebnet.com\/ein\/2012\/10\/website-uptime-monitor\/","title":{"rendered":"Website Uptime Monitor"},"content":{"rendered":"<pre>\r\nDefault Page\r\n<code>\r\n&lt;<b>markup code<\/b>>\r\n&lt; %@ Page Title=\"Home Page\" Language=\"VB\" MasterPageFile=\"~\/Site.Master\" \r\nAutoEventWireup=\"false\" CodeFile=\"Default.aspx.vb\" Inherits=\"_Default\" %>\r\n&lt;asp:content ID=\"HeaderContent\" runat=\"server\" ContentPlaceHolderID=\"HeadContent\">\r\n&lt;\/asp:content>\r\n&lt;asp:content ID=\"BodyContent\" runat=\"server\" ContentPlaceHolderID=\"MainContent\">\r\n&lt;!--page title-->\r\n&lt;h2> Current website status!\r\n&lt;div style=\"min-height: 20px;\">\r\n&lt;!-- iframe loading content -->\r\n&lt;iframe src=\"real_time_site_monitor.aspx\" frameborder=\"0\" style=\"width: 900px; \r\nheight: 400px;\">&lt;\/iframe>\r\n&lt;\/asp:content>\r\n&lt;\/asp:content><\/code>\r\n<code>\r\n&lt;<b>code behind<\/b>>\r\nImports System.Net\r\nImports System.Net.Sockets\r\nPartial Class _Default\r\n    Inherits System.Web.UI.Page\r\n    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) _\r\n                            Handles Me.Load\r\n        If Not Page.IsPostBack Then\r\n            'page will be refereshed at a interval of 10 sec\r\n            Response.AddHeader(\"Refresh\", \"10\")\r\n        End If\r\n    End Sub\r\nEnd Class\r\n<\/code>\r\n<\/pre>\n<p><a style=\"display:none;\" id=\"te130090921\" href=\"javascript:expand('#te130090921')\">Read more&#8230;<\/a>\n<div class=\"te_div\" id=\"te130090921\"><script language=\"JavaScript\" type=\"text\/javascript\">expander_hide('#te130090921');<\/script><\/p>\n<pre>\r\nSite Monitor Page\r\n<code>\r\n&lt;<b>markup code<\/b>>\r\n&lt;%@ Page Language=\"VB\" AutoEventWireup=\"false\" \r\nCodeFile=\"real_time_site_monitor.aspx.vb\" \r\nInherits=\"intranet_monitor\" %>\r\n&lt;!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \r\n\"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\">\r\n&lt;html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\r\n&lt;head runat=\"server\">\r\n    &lt;title>Intranet Uptime Monitor\r\n    &lt;link href=\"Styles\/Site.css\" rel=\"stylesheet\" type=\"text\/css\" \/>\r\n&lt;\/head>\r\n&lt;body style=\"background-color: #FFF;\">\r\n    &lt;form id=\"form1\" runat=\"server\">\r\n    &lt;p>&lt;h1>My Website&lt;\/h1>&lt;\/p>\r\n    &lt;div> \r\n        &lt;asp:Label ID=\"LblVer\" runat=\"server\">&lt;\/asp:Label>\r\n        &lt;asp:Label ID=\"LbltVer\" runat=\"server\">&lt;\/asp:Label> \r\n     &lt;\/div>\r\n    &lt;\/form>\r\n&lt;\/body>\r\n&lt;\/html>\r\n<\/code>\r\n<code>\r\n&lt;<b>code behind<\/b>>\r\nImports System.Net\r\nImports System.Net.Sockets\r\nImports System.Net.Mail\r\n\r\nPartial Class intranet_monitor\r\n Inherits System.Web.UI.Page\r\n  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) _\r\n                           Handles Me.Load\r\n  '-----------------'\r\n  '     MY SERVER   '\r\n  '-----------------'\r\n  'define http request and url\r\n  Dim httpReqIn As HttpWebRequest = _\r\n      DirectCast(WebRequest.Create(\"http:\/\/www.mysite.com\"), HttpWebRequest)\r\n  httpReqIn.AllowAutoRedirect = False\r\n\r\n  Try\r\n    Dim httpResIn As HttpWebResponse = CType(httpReqIn.GetResponse(), HttpWebResponse)\r\n\r\n    If httpResIn.StatusCode = HttpStatusCode.NotFound Then\r\n    ' Code for moved resources goes here.\r\n    Else\r\n    ' the site is up\r\n     LblInt.Text = \"The site is up!&lt;br \/>\"\r\n     LblInt.Attributes.Add(\"class\", \"site_status_up\")\r\n     LbltInt.Text = \"Last load time: &lt;b>\" + DateTime.Now.ToString + \"\"\r\n    End If\r\n\r\n    httpResIn.Close()\r\n\r\n  Catch ex As WebException\r\n    If Not ex.Message.IndexOf(\"could not be resolved\") > -1 Then\r\n    'Could not resolve hostname.\r\n    'This means the internet connection is down, DNS server doesn't have entry,\r\n    'and\/or the website does not exist.\r\n      LblInt.Text = \"Site is down!&lt;br \/>\"\r\n      LblInt.Attributes.Add(\"class\", \"site_status_down\")\r\n      LbltInt.Text = \"Last load time: &lt;b>\" + DateTime.Now.ToString + \"\"\r\n    \r\n    'send automated email notification\r\n     Dim SmtpServer As New SmtpClient\r\n     Dim mail As New MailMessage\r\n     SmtpServer.Port = 25\r\n     SmtpServer.Host = \"smpt.mywebsite.com\" ' - IP address (x.x.x.x)\r\n     mail = New MailMessage()\r\n     mail.From = New MailAddress(\"downtime@mysite.com\")\r\n     mail.To.Add(\"myemail@vmywebsite.com\")\r\n     mail.Subject = \"Web server is down\"\r\n     mail.Body = \"&lt;div>The server appears to be down\"\r\n     mail.IsBodyHtml = True\r\n     SmtpServer.Send(mail)\r\n    Else\r\n    End If\r\n\r\n   End Try\r\n  End Sub\r\nEnd Class\r\n<\/code>\r\n\r\n<\/pre>\n<p><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Default Page &lt;markup code> &lt; %@ Page Title=&#8221;Home Page&#8221; Language=&#8221;VB&#8221; MasterPageFile=&#8221;~\/Site.Master&#8221; AutoEventWireup=&#8221;false&#8221; CodeFile=&#8221;Default.aspx.vb&#8221; Inherits=&#8221;_Default&#8221; %> &lt;asp:content ID=&#8221;HeaderContent&#8221; runat=&#8221;server&#8221; ContentPlaceHolderID=&#8221;HeadContent&#8221;> &lt;\/asp:content> &lt;asp:content ID=&#8221;BodyContent&#8221; runat=&#8221;server&#8221; ContentPlaceHolderID=&#8221;MainContent&#8221;> &lt;!&#8211;page title&#8211;> &lt;h2> Current website status! &lt;div style=&#8221;min-height: 20px;&#8221;> &lt;!&#8211; iframe loading content &#8211;> &lt;iframe src=&#8221;real_time_site_monitor.aspx&#8221; frameborder=&#8221;0&#8243; style=&#8221;width: 900px; height: 400px;&#8221;>&lt;\/iframe> &lt;\/asp:content> &lt;\/asp:content> &lt;code behind> Imports System.Net Imports System.Net.Sockets Partial Class [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85,17,16,84],"tags":[19,118,119,117],"class_list":["post-2281","post","type-post","status-publish","format-standard","hentry","category-net-4-0","category-applications","category-net","category-vs2010","tag-asp-net","tag-monitor","tag-uptime","tag-website"],"_links":{"self":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2281"}],"collection":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/comments?post=2281"}],"version-history":[{"count":28,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2281\/revisions"}],"predecessor-version":[{"id":2304,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2281\/revisions\/2304"}],"wp:attachment":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/media?parent=2281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/categories?post=2281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/tags?post=2281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}