Analysis of Automatic startup features of ASP. NET4 and asp. net4 features

Source: Internet
Author: User

Analysis of Automatic startup features of ASP. NET4 and asp. net4 features

The function of automatically starting a web application without waiting for an external client to access the web server. This helps you provide a faster response experience for the first visitor, avoiding writing custom scripts for "warm up" servers and preparing any data cache. It can be used for any type of ASP. NET applications, including applications based on ASP. NET Web Forms and ASP. net mvc.

Automatically Start Web applications in ASP. NET 4

Some web applications need to load a lot of data or perform initialization before they can process user access. Today, ASP. NET developers often use the "Application_Start" event handler function in the Global. asax file of the application to perform these tasks (this event is triggered when the first request is executed ). They either design custom scripts and periodically send fake requests to the application to "wake it up" to execute the code before the customer accesses it, or let the unfortunate first visitor wait until the logic is executed to process the request (which can cause a long delay for these users ).

ASP. NET 4 has a new feature called "auto-start", which can better solve this scenario. It can be released in IIS 7.5 (with Windows 7 and Windows Server 2008 R2) run ASP.. NET 4. This Automatic startup feature provides a controllable way to start an application workflow, initialize an ASP. NET application, and then accept HTTP requests.

Configure an ASP. NET 4 Application to automatically start

To use the Automatic startup feature of ASP. NET 4, you must first configure the IIS application pool worker process so that the applications running in it are automatically started when the web server is first loaded. The configuration method is to open the applicationHost of IIS 7.5. config File (C: \ Windows \ System32 \ inetsrv \ config \ applicationHost. in <applicationPools>, add the startMode = "AlwaysRunning" attribute:

< applicationPools>     < add name="MyAppWorkerProcess" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" />  < /applicationPools> 

Worker.

A single IIS application pool worker can host multiple ASP.. NET application. You can add the serviceAutoStartEnabled = "true" attribute to the <application> of the corresponding application to specify which applications you want to automatically start when the worker process is loaded:

< sites>     < site name="MySite" id="1">       < application path="/" serviceAutoStartEnabled="true" serviceAutoStartProvider="PreWarmMyCache" />    < /site>  < /sites> < serviceAutoStartProviders>     < add name="PreWarmMyCache" type="PreWarmCache, MyAssembly" />  < /serviceAutoStartProviders> 

The aboveServiceAutoProvider = "PreWarmMyCache"The property references a provider configuration in the config file, allowing you to configure a custom class, which is used to encapsulate any "warm up" logic of the application. This class is automatically called when the worker process and application are pre-loaded (before receiving any external web request, it can be used to execute any initialization or cache loading logic that you want to execute before accepting and processing the request:

public class PreWarmCache : System.Web.Hosting.IProcessHostPreloadClient {   public void Preload(string[] parameters) {      // Perform initialization and cache loading logic here...    }  } 

IIS starts the application to such a State, in which it cannot accept the request until your "warm up" logic is complete. After the initialization code in the Preload method is returned, the ASP. NET application is marked as a processing request.

You can also combine the New Automatic startup "warming up" feature with the IIS7 Application Request Routing (ARR) extended load balancing feature, it is used to initialize the application. After receiving the HTTP request, it sends a signal to the Load balancer. At this time, the server can put the web farm to process the request.

Conclusion

ASP. NET 4 and IIS 7.5 automatically start new features provide a clearly defined way to allow you before any end users access your application, running a costly application startup and pre-Cache logic allows you to "warm up" the application from the very beginning, providing a consistent high-performance experience.

I hope this article will help you better understand the Automatic startup feature.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.