10.16. Autostart Web Applications

Some ASP.NET applications perform a lot of startup work (usually in Global.asax's Application_Load() method), such as preloading or caching data. ASP.NET 4.0 introduces a new feature called autostart that enables you to define code to be run as soon as your application is installed (or the app pool is recycled). Until this startup work has completed, ASP.NET will prevent access to the application.

Not all applications will be able to benefit from this facility, though, because they must do the following:

  • Be running on Windows Server 2008 R2 and IIS 7.5

  • Be written in ASP.NET 4.0

To use autostart, add the following setting to the applicationHost.config file (at C:WindowsSystem32inetsrvconfig):

<applicationPools>
    <add name="ApressAppPool" startMode="AlwaysRunning"" />
</applicationPools>

You must now specify the sites to be automatically started and the serviceAutoStartProvider they should use:

<sites>
  <site name="ApressSite" id="5">
    <application path="/"
        serviceAutoStartEnabled ="true"
        serviceAutoStartProvider ="PrewarmMyCache" >
            </application>
  </site>
</sites>

An autostart class is created by implementing the IProcessHostPreloadClient interface and added as a provider in applicationHost.config:

<serviceAutoStartProviders >
    <add name="StartmeUp"
        type="Apress.CustomInitialization, ASPStartup" />
</serviceAutoStartProviders >

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.122.82