Use the auto-start feature of ASP. NET 4 To resolve slow first-time access to ASP.

Source: Internet
Author: User

Some Web applications need to load a lot of data before they can handle user access, or do some expensive initialization processing. Developers who use ASP. NET today often use the "Application_Start" event handler in the application's Global.asax file (which is triggered when the first request executes). They either design a custom script, periodically send a fake request to the app, to "wake it Up", execute the code before the customer accesses it, or let the unfortunate first visitor wait for the logic to execute before processing its request (which can cause a long delay for these users). Wake

There is a new feature called "Autostart (Auto-start)" in ASP. NET 4, which is a good solution to this scenario, and can be used on IIS 7.5 (published with Windows 7 and Windows Server R2), which runs ASP. NET 4 o'clock. This autostart feature provides a controllable way to initiate an application worker process, initialize an ASP. NET application, and then accept the HTTP request.

Configure an ASP. NET 4 application to start automatically

To use the ASP. NET 4 Auto-start feature, you first configure the IIS application pool worker process to start automatically when the Web server is first loaded by the application that is running in it. The configuration method is:

1. Locate the application pool where the site resides, and then right-click the Advanced Settings

2. Modify the boot mode to: alwaysrunning

If you run Windows Task Manager and click the "Show processes for all users" check box, and then the above dialog point is determined, you will see a new "w3wp.exe" worker process start up in a moment.

A single IIS application pool worker process can host multiple ASP. NET apps, and you can set auto-start to True by using the advanced settings in the site:

Next, to set the logic that will be executed when the site preloading starts, in IIS it is to add a custom Serviceautostartprovider, as follows:

First, implement a class that inherits from Iprocesshostpreloadclient:

One of the things that this code does is to have the system automatically access a Web site when it's hot, and let IIS do it yourself.

In the Serviceautostartproviders section, open the collection, click Add, write the name and the class name, remember, because the next step is to fill in this name.:

Open the collection in the Sites node, select the site we need to set, open the Applicationdefaults node in the Properties box below, set serviceautostartenabled to True, Fill in the name of the Serviceautostartprovider that you added in the previous step.

The hot start to this site has been configured.

Some issues that you may encounter when you configure it, as well as registration matters:

1. It is best to wrap all in the code with try{}catch{} because if the exception thrown here causes the application to stop.

2. Status of the operation we can view it from the event manager, or write the state of the log record running in the code itself.

3. What is done in this class does not refer to the start of the site, does not execute the application's life cycle, that is, Application_Start and other life cycle processes are not invoked. So in this case we'll call the new one to request this site.

For more. NET development information, please focus on near/spacebuilder development and sharing community "

Use the auto-start feature of ASP. NET 4 To resolve slow first-time access to ASP.

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.