An analysis of the automatic starting characteristics of ASP.NET4--practical skills

Source: Internet
Author: User

Starts automatically, initializing the Web application without waiting for the ability of the external client to start when accessing the Web server. This can help you provide a quicker response experience to the first visitor, avoid writing custom scripts to "preheat (warm Up)" servers and prepare any data cache. It can be used for any type of asp.net application, 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 do some expensive initialization before they can handle user access. Developers who use ASP.net today often use the "Application_Start" event handler in the application's Global.asax file to do this (the event is triggered when the first request executes). They either design custom scripts and periodically send false requests to the application. To "Awaken it (wake it Up)" to execute the code before the customer accesses it, or let the unfortunate first visitor wait for the logic to finish before processing its request (which can cause a long delay to these users).

ASP.net 4 has a new feature called Automatic startup (Auto-start) that you can use to better address this scenario and run ASP.net 4 o'clock on IIS 7.5 (published with Windows 7 and Windows Server 2008 R2). This autostart feature provides a controllable way to start an application worker process, initialize the ASP.net application, and then accept the HTTP request.

Configure a ASP.net 4 application to start automatically

To use the ASP.net 4 autostart feature, you first configure the IIS application pool worker process so that the application running in it starts automatically when the Web server is first loaded. The configuration method is to open the IIS 7.5 applicationhost.config file (C:\Windows\System32\inetsrv\config\applicationHost.config), in the appropriate < Applicationpools>, add a startmode= "alwaysrunning" attribute:

< applicationpools>  
   < add name= "myappworkerprocess" managedruntimeversion= "v4.0" startmode= " Alwaysrunning "/>  
</applicationpools> 

If you run Windows Task Manager, click the "Show all user's process" checkbox, and then save the StartMode property of the ApplicationHost.config file, and you'll see a new "w3wp.exe" in the instant the file is saved. The work process has started.

A single IIS application pool worker process can host multiple asp.net applications, and you can add a serviceautostartenabled= "true" attribute in the corresponding application's < application>. To specify which applications you want to start automatically 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 above serviceautoprovider= "Prewarmmycache" attribute refers to a provider (provider) configuration in the config file, allowing you to configure a custom class that encapsulates any " Preheat (warming up) logic. This class is invoked automatically when the worker process and the application is preloaded (before any external Web requests are received), and can be used to perform any initialization or cache load logic that you want to perform 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 launches the application into a state where it cannot accept requests until your "preheat (warming up)" logic is complete. After the initialization code in the Preload method finishes running, the ASP.net application is marked as a processing request.

You can also combine the new autostart "warming up" feature with the load-balancing function of the IIS7 application request-oriented (application requests Routing, ARR) extension, which is used to initialize the application, after the HTTP request is accepted, Signal to the load balancer, at which point the server can put the Web farm to process the request.

Conclusion

The new autostart features of ASP.net 4 and IIS 7.5 provide a well-defined way to run expensive application startup and caching logic before any end user accesses your application, which allows you to start by "preheat (warmed up)". Provides a consistent, high-performance experience.

Hopefully this article will help you with a better understanding of the autostart 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.