Run Application_Start immediately when application

2019-01-25 09:03发布

问题:

We are doing some caching operations in the application_start phase in the application. So all the cache is going away when the application pool restarts. Is it possible to trigger application_start when the application pool restarts or do you have better ideas to solve this problem ?

回答1:

You could use Application Initialization for IIS 7.5, it borrows functionality from IIS8, or if you are using ASP.NET 4.0 + there is application auto start.

For ASP.NET 2.0 i 3.5 there is a IMO somewhat hackish solution, you can log application pool recycle in Event log and then in event log set a task that will be performed on that event, here are the details



回答2:

Application_Start is called only at the first request. I'm not sure it's a good idea to cache something if no requests are made.

I would you simply load the cache upon the first request.
Your CacheManager could decide if it's need to load it's data automatically.

Are you afraid the first request will be slower ?.



标签: c# .net iis iis-7