Force Application Start on Azure Web Role

孤人 提交于 2019-11-29 07:27:07

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.

Jordi, I've recently experienced the same issue.

Based on my test Application_Start() is called ONLY when the 1st request ISS for the WebApp. (if you try to start VS in Debug without it open any page (see options in proj/debug), you will see that Application_Start() won't be called also if you don't run the WebApp in Azure)

I suppose that you need doing somethings when the WebRole start, well put your code in the WebRole.cs ;) Here you can override OnStart() and OnStop() and put your code that wiil be execuded when the WebRole will start.

I've used this way to run a BakgroundWorker that do some scheduled tasks, independently from IIS.

I hope this help. Davide.

Note: 1 - if you dont'have a WebRole.cs create it in the root of project and write inside: public class WebRole : RoleEntryPoint { public override bool OnStart() { ...your code... return base.OnStart(); } }

2 - If you need to debug the code mind that you need to run VS in debug with the Azure project that refer to WebApp as a "Run Project", otherwise the WebRole will not be called

You could try putting some code in your WebRole.cs to request some URLs from your website. I've tried that, and it seems to work somewhat. But it's a pain to debug, so I never got it really nailed down.

Another option would be to use IIS Application Initialization. You can't use it on IIS 7.5, but you can get IIS 8 if you upgrade your roles to Windows 2012 (set osFamily="3" in your .cscfg).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!