ASP.NET Perfect solution for slow first access (MVC, web API)


Problem phenomenon

visit When a web project is accessed for the first time, it will be very slow to visit again after a period of idle time.

Cause of the problem

This is caused by IIS recycling. When you access again, the initialization will take time, so the access will be slow. When you access the second time, you do not need the initialization, so it becomes faster.

terms of settlement

IIS application initialization will automatically open a new application pool after the website is first created or the application pool of the corresponding website is recycled, and start website initialization to simulate a normal request to keep the website online.

Modify configuration in IIS

1. Modify and enable application pool (alwaysrunning): ensure that the application pool can restart automatically after it is first created or recycled.

2. Modify the idle timeout of 1740 minutes: there is no request to release resources for a long time, so it can not be modified.

3. Modify and enable website program preload (true): ensure that the website can respond to the preload action after the program pool is started.

I think some blogs will set the process model / idle timeout to 0 or very long, which is not very good. Idle timeout means that if your application does not process or accept the request, it will enter the idle state. This state can be maintained for a long time. If it exceeds this time, the process will delete and release all content from memory. If it is set to 0, it will not remain idle for a long time. If there is a memory leak in the code, it will remain idle for a long time and occupy the server completely. The setting time is too long, there is no request for a long time, and it also takes up this memory, which is a bit wasteful. According to the above changes, it will start in seconds. This modification is also applicable to MVC, web API and other IIS projects

First visit to projects prior to iis8 ASP.NET Application will be slow

This problem may exist in previous programs, but it’s basically gone now, because starting with Windows 8, it’s no longer necessary to sign CSP.
Microsoft Authenticode: Microsoft Authenticode is designed to help users ensure who actually created the code they are running, especially for code downloaded or running on the Internet, and to verify that the code has not been changed or tampered with since it was published. For example, programs that are digitally signed, maliciously tampered with, and then redistributed online will display a warning to users before they run.

Problem phenomenon

ASP.NET The first time the page is visited, it is very slow, and the time can last tens of seconds to several minutes

Cause of the problem

When some Authenticode signed. Net assembly needs to be called in the program, it needs to connect to the external network to verify the digital certificate. When the server is unable to connect to the Internet, the certificate verification process needs to wait until timeout.

terms of settlement

This solution is provided by Internet developer support team of Microsoft APAC technical support center zh-cn/2011/04/24/asp-net/)
Please use both of the following aspnet.config Add the following to the file.



<?xml version="1.0" encoding="utf-8"?>

      <generatePublisherEvidence enabled="false"/>

Modify the following registry key values and restart IIS service, open the registry regedit, find the following address, modify state to 00023e00, and the original is 00023c00
[HKEY_USERS\S-1-5-20\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing]

Then remember to restart the application pool


The above is the whole content of this article. I hope that the content of this article has some reference learning value for your study or work. Thank you for your support for developepaer.