kacalapy
kacalapy

Reputation: 10134

c# ping a website? (keep-alive service)

is there a way in c# to be able to ping a url every 15 minutes and get a response back from the server?

i want to try to see if .net can be used to build a simple tool to have asp.net websites invoke a re-build so that the first user doesn't incur the load penalty when the application is started.

or if anyone has an alternative method of accomplishing the same goal... thoughts? tips? ideas?

Upvotes: 6

Views: 12938

Answers (6)

Brad Christie
Brad Christie

Reputation: 101604

Typically the person pushing a release should visit after they've uploaded the site just for test sake (make sure nothing bombed out). But if you're looking for a programmatic approach, WebClient may be helpful...

using (WebClient client = new WebClient())
{
  client.DownloadString("http://wwww.sitename.com/");
}

Then make it an exe and use the windows scheduler to run it. Could even put this in a WinService and report status to log files.

Update:

It looks like VS2012 now opens the page after a publish, making those pushing the site be the first-request.

Also, if you find you're having to visit it that frequently (every 15 minutes as mentioned in question) you may want to look in to reconfiguring the IIS/AppPool and change the cycle time to something longer. IIS natively conserves resources that are not used, and so if a site hasn't been queried in a while it will actually release the memory for another application to use.

Upvotes: 9

Jesse C. Slicer
Jesse C. Slicer

Reputation: 20157

You can NGEN your ASP.NET assemblies and combine that with Hector's warm-up answer.

Upvotes: 0

Rob Stevenson-Leggett
Rob Stevenson-Leggett

Reputation: 35679

I'd install curl and use a scheduled task to do what you want.

I've combined it with powershell to restart app pools too.

Upvotes: 1

Hector Correa
Hector Correa

Reputation: 26690

You might not need to write your own:

http://learn.iis.net/page.aspx/688/using-the-iis-application-warm-up-module/

Upvotes: 5

cjk
cjk

Reputation: 46425

You can just fire off a WebRequest - a ping won't get the website to rebuild.

Upvotes: 1

Adam
Adam

Reputation: 629

You could create a HttpWebRequest and use something like Quartz.NET to schedule it.

Upvotes: 3

Related Questions