Administrator Account posted on March 30, 2010 19:55
Does your DotNetNuke (DNN) or ASP.net website running on the Microsoft .Net technology perform poorly when someone visits it? Have you tried performance tuning without success?
Most often, these DNN performance issues are due to the website application code having to load into memory. Typically, an ASP.net application stays running in memory until a certain period of inactive time has elapsed. At this point, the operating system removes the application code from memory until the next time a website application request occurs. In a shared hosting environment, this allows for more efficient usage of memory resources for the websites which are active.
However, the downside for your inactive website is usually a big performance hit the first time your website application loads into memory again. A typical solution used by many website owners to overcome this performance problem is to use a “Keep Alive” service, which forces your application code to stay in memory.
“Keep Alive” services accomplish this by “pinging” your website at configured intervals. This simply keeps the website application from reaching the set “inactivity setting” where it is removed from memory.
While Microsoft does have a Application Warm-Up feature in progress for the IIS 7.5 environment, not everyone has their IIS environment upgraded to the 7.5 version. Also, those sites running on shared hosting environments may not even have this option available for them to use.
There are websites available which will provide this service for you, some free, many for a fee. The reality though is that it is very simple to create your own “Keep Alive” service.
All this requires is a copy of the Visual Basic Express development environment, which you can download for free from Microsoft’s website. Once downloaded and installed, simply create a new console application, which will create a new module file by default.
Simply replace the default code Visual Studio added to this new module with the code below. You can add lines in the Main procedure to check as many sites as needed.
Compile the application and then copy the application executable file from the project bin folder to a place on your hard drive. You can use Windows scheduler to run the application every 5, 10 or 15 minutes. It will then ping your website for you automatically.
As an added benefit, the application will send you an email if it does not receive a valid response code from the ping operation. Using these emails gives you a simple site monitor, so that you can know if your site goes down for any reason and approximately when based on the time of the email.
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Net.Mail
Module Startup
Sub Main()
Call CheckOneSite("http://www.part-time-work-at-home-opportunities.com/keepalive.aspx")
Call CheckOneSite("http://www.site2.com")
Call CheckOneSite("http://www.site3.com")
Call CheckOneSite("http://www.siten.com")
End Sub
Private Sub CheckOneSite(ByVal pUrl As String)
Try
' Create a request for the URL.
Dim lRequest As WebRequest = WebRequest.Create(pUrl)
' If required by the server, set the credentials.
lRequest.Credentials = CredentialCache.DefaultCredentials
' Get the response.
Dim lResponse As HttpWebResponse = _
CType(lRequest.GetResponse(), HttpWebResponse)
'Check the response code
If lResponse.StatusCode <> HttpStatusCode.OK Then
Dim lSb As New StringBuilder
lSb.AppendFormat("Received an invalid Http response code: {0}", _
lResponse.StatusCode.ToString)
Call SendNotification(pUrl, lSb.ToString)
End If
lResponse.Close()
Console.WriteLine(Now.ToString & " - Site Check Ok: " & pUrl)
Catch ex As Exception
Call SendNotification(pUrl, ex.Message)
End Try
End Sub
Private Sub SendNotification(ByVal pUrl As String, ByVal pMessage As String)
'Start by creating a mail message object
Dim MyMailMessage As New MailMessage()
'From requires an instance of the MailAddress type
MyMailMessage.From = New MailAddress("<email>@gmail.com")
'To is a collection of MailAddress types
MyMailMessage.To.Add("<email>@gmail.com")
MyMailMessage.Subject = String.Format("SiteChecker error: {0}", pUrl)
MyMailMessage.Body = pMessage
'Create the SMTPClient object and specify the SMTP GMail server
Dim SMTPServer As New SmtpClient("smtp.gmail.com")
SMTPServer.Port = 587
SMTPServer.Credentials = New _
System.Net.NetworkCredential("<email>@gmail.com", "<password>")
SMTPServer.EnableSsl = True
Try
SMTPServer.Send(MyMailMessage)
Catch ex As SmtpException
Console.WriteLine(ex.Message)
End Try
End Sub
End Module