How to keep ASP.Net sites from taking so long to load

If you’ve deployed a .Net website, you might find that when you visit your website it will take about 20 seconds to load, which seems more like minutes as you sit there waiting and nothing seems to be happening. This is common with .Net sites and IIS because IIS will unload any applications that haven’t been used recently. By default if your site has not been accessed in the last 20 minutes, then IIS can unload it from memory to free up space for other operations.

To prevent this, I like to setup a script on the server and setup a scheduled task to run every few minutes to load a page from my website. This doesn’t do anything major, but it does cause IIS to reset its counter for how long it has been since the website was last accessed. If I run this script every 5 minutes (it could be every 15 or any value less than 20, but I like 5 since my server doesn’t have much else to do except make sure these websites are available.

In this sample we’ll assume I have 4 websites in IIS that need to I want to keep active. You can modify this for more or less sites as needed:

First create a vbs file and put it somewhere on your computer. I’ll put it in C:/tasks/

Url = "http://www.Site1.com"

Set xml = CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", Url, False

xml.Send

set xml = Nothing

Url2 = "http://www.Site2.com"
Set xml2 = CreateObject("Microsoft.XMLHTTP")
xml2.Open "GET", Url2, False

xml2.Send
set xml2 = Nothing

Url3 = "http://www.site3.com"
Set xml3 = CreateObject("Microsoft.XMLHTTP")
xml3.Open "GET", Url3, False

xml3.Send
set xml3 = Nothing

Url4 = "http://www.site4.com"
Set xml4 = CreateObject("Microsoft.XMLHTTP")
xml4.Open "GET", Url4, False

xml4.Send
set xml4 = Nothing

Save this file as C:/tasks/siteRefresh.vbs

Next create another file in the same folder with this content:

siteRefresh.vbs

Yes that is all. It is just going to call your vbs script so you just need the name of your first file as long as they are in the same folder. Save this one as C:/tasks/siteRefresh.bat

Now open your windows schedule tasks window (I’m using Windows 2003 Server) by going to Start / Control Panel / Administrative Tools / Task Scheduler. Click ‘Task Scheduler Library’ on the right side of the window then click ‘Create Task’ on the right menu.
Set the name to “Site Refresher”. Make sure the check box is checked for ‘Run whether user is logged on or not’ and click OK.
Click the ‘Triggers’ tab, and click ‘New’ to create a trigger.
Set your trigger to Daily, then a the bottom of the screen check the box for ‘Repeat every’, and set the value for 5 minutes for a duration of ‘1 day’. Click Ok.
Open the ‘Actions’ tab and click ‘New’ then select ‘Start a program’. Use the browse button to browse to your .bat file. I’m selecting ‘C:/tasks/siteRefresh.bat’. The click ‘Ok’.

You are finished. As you close out of the window you will be asked to enter your user name and password.

Now your sites will get loaded every 5 minutes and those long 20 second load times should not occur anymore.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s