强制应用开始在Azure上的Web角色 [英] Force Application Start on Azure Web Role
问题描述
我有在Azure上的Web角色,我想强制的Application_Start无需等待第一个请求。
我设法设置了自动启动属性设置为true在我的网站
自动开始在Azure上WebRole 一个WCF
不过的Application_Start不叫,直到第一个请求来了。
我不知道到底,如果我在这里缺少一些重要的东西。服务器是W2008 R2和IIS版本是7.5
谢谢!
SOLUTION
我把解决方案code在这里。我希望能帮助别人。我只是增加了一个WebRole.cs,只是把那个code到执行ping每30秒。请netice我浏览Service.svc,因为这是我的终点,您的端点可能是另外一个。请注意我所要求的端点1。如果你有一个以上的端点,您应该查看该行。
公共类WebRole:RoleEntryPoint
{
公共覆盖无效的run()
{
VAR localuri =新的URI(的String.Format(HTTP:// {0} /Service.svc,RoleEnvironment.CurrentRoleInstance.InstanceEndpoints [端点1] IPEndpoint)); 而(真)
{
尝试
{
VAR请求=(HttpWebRequest的)WebRequest.Create(localuri);
request.Method =GET;
变种响应= request.GetResponse();
}
赶上{}
System.Threading.Thread.Sleep(30000);
}
} 公众覆盖布尔的OnStart()
{
返回base.OnStart();
}
}
在第一个请求到达的IIS才会启动。解决方法是的OnStart
或 RoleEntryPoint
后代内发送HTTP请求到同一个虚拟机 - 即使用很容易的WebRequest
或等价类。
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();
}
}
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.
这篇关于强制应用开始在Azure上的Web角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!