Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
577 views
in Technique[技术] by (71.8m points)

iis 7.5 - Force Application Start on Azure Web Role

I have a web role on azure and I would like to force a Application_Start without waiting for the first request.

I managed to set the "Start Automatically" property to true on my site

AutoStart a WCF on Azure WebRole

But the Application_Start is not called until the first request comes.

I don't know exactly if I am missing something important here. The server is a W2008 R2 and the IIS version is 7.5

Thanks!

SOLUTION

I put the solution code here. I hope will help someone. I just added a WebRole.cs and just put that code to perform a ping every 30 seconds. Please netice I'm browsing Service.svc because this is my endpoint, your endpoint could be another one. Notice I'm asking for "Endpoint1". If you have more than one endpoints, you should review that line.

public class WebRole : RoleEntryPoint
{        
    public override void Run()
    {            
        var localuri = new Uri( string.Format( "http://{0}/Service.svc", RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint ) );

        while (true)
        {
            try
            {                    
                var request = (HttpWebRequest)WebRequest.Create(localuri);
                request.Method = "GET";
                var response = request.GetResponse();
            }
            catch { }
            System.Threading.Thread.Sleep(30000);
        }            
    }

    public override bool OnStart()
    {               
        return base.OnStart();
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The IIS will only start when the first request arrives. The workaround is to send an HTTP request to the same VM from within OnStart or your RoleEntryPoint descendant - that's easy using WebRequest or equivalent class.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...