Application_Start() event in global.asax

烂漫一生 提交于 2019-12-06 01:43:38

问题


Hai guys, My website has thousands of users... I have implemented a background task of sending mails to every user once a day ... I followed this link to do this...

http://www.codeproject.com/KB/aspnet/ASPNETService.aspx

My question is will Application_Start() will be fired for every user hitting my website... If so every user will be receiving a n number of mails daily so i want to avoid it...


回答1:


The Application_Start and Application_End methods are special methods that do not represent HttpApplication events. ASP.NET calls them once for the lifetime of the application domain, not for each HttpApplication instance.

So When first user will open the site it will hit the application_start method after that it will not.

I will add that what you are trying to do is risky. If you want to do batch email sending then you may want to think about Scheduler which can send emails daily.




回答2:


Application_Start only runs when the first person goes to the site and when the app_pool refreshes.

It does not happen on every hit to the site.

you might want to think of something like http://www.webcron.org/ for a cron-like system to schedule tasks.




回答3:


It should be on the Application_BeginRequest plus a DB storing the state for every visitor. But the most appropriate is on Scheduler.




回答4:


For the full picture - here is list of all events which can be fired in global.asax:

http://aspalliance.com/1114_Understanding_the_Globalasax_file.3



来源:https://stackoverflow.com/questions/1794349/application-start-event-in-global-asax

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