Although the Sandrino solution can work ... here is a solution that does not require the web role to be run in high security mode, and also forces the application to start when webrole starts (before the first user visits the site), This solution will also work on Earlier versions of IIS / Windows Server that do not require IIS 8 Application Initialization.
Just add WebRole.cs with the following content:
using System; using System.Net; using System.Net.Security; using System.Threading; using Microsoft.WindowsAzure.ServiceRuntime; namespace Website { public class WebRole : RoleEntryPoint { public override bool OnStart() { WarmUpWebsite("HttpIn"); return base.OnStart(); } public override void Run() { while (true) { WarmUpWebsite("HttpIn"); Thread.Sleep(TimeSpan.FromMinutes(1)); } } public void WarmUpWebsite(string endpointName) { // Disable check for valid certificate. On som sites live HTTP request are redirected to HTTPS endpoint. And when running on staging SSL the certificate is invalid. RemoteCertificateValidationCallback allowAllCertificatesCallback = (sender, certificate, chain, sslPolicyErrors) => true; ServicePointManager.ServerCertificateValidationCallback += allowAllCertificatesCallback; try { RoleInstanceEndpoint endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[endpointName]; string address = String.Format("{0}://{1}:{2}", endpoint.Protocol, endpoint.IPEndpoint.Address, endpoint.IPEndpoint.Port); //This will cause Application_Start in global.asax to run new WebClient().DownloadString(address); } catch (Exception) { // intentionally swallow all exceptions here. } ServicePointManager.ServerCertificateValidationCallback -= allowAllCertificatesCallback; } } }
Credits go to: http://weblogs.thinktecture.com/cweyer/2011/01/poor-mans-approach-to-application-pool-warm-up-for-iis-in-a-windows-azure-web- role.html
While (true) can be replaced with the Sandrino approach or you can disable the application pool timeout: http://blog.smarx.com/posts/controlling-application-pool-idle-timeouts-in-windows-azure
Thomas jespersen
source share