Be careful about the pitfalls when publishing an ASP.NET website. Why does every page freeze when you first open it after the website is published? How to solve the frequent loss of ASP.NET sessions? It has certain reference value. Interested friends can refer to
Development tools: VS2010, MVC4.0, SQLSERVER2008
Server: Windows server 2012, IIS8, SQLSERVER2012
1. After publishing, each page is stuck for 50 seconds or more when it is opened for the first time. However, it is very fast the second time it is opened.
Estimated reason: slow compilation speed , but publishing on a machine with a VS environment is not so stuck.
Solution:
Use a higher version of VS, "precompile during release"; use the Application Initialization function of IIS8 1. Using VS2017 "Precompile during release"
I encountered an error when publishing:
It is an error to use a section registered with allowDefinition='MachineToApplication' outside the application level. This error can be caused if the virtual directory is not configured as an application in IIS.
Solution: Comment the following code in web.config when publishing
<!--<authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="2880" /> </authentication>-->
2. Use Application Initialization function of IIS8
Solution to slow first access to ASP.NET website
2. ASP.NET session frequent loss problem
Symptom: The session is lost about 30 seconds after logging in, and you need to log in again.
Solution: ASP.NET has several session state modes. The default is "InProc mode". Change it to "StateServer mode" and the problem will be solved.
1. off mode
means closing the Session.
To close the session for the whole site, you can write in the
To close the Session on a page, you can add on the page:
<%@ Page EnableSessionState="false" %>
2. InProc mode (default mode)
If SessionState Mode is not configured in the Web.config file, the default is InProc mode.
If you want to customize the parameters of InProc mode, you need to write the Web.config file, for example:
cookieless sets whether to allow cookies not to be used, and timeout sets the timeout in minutes.
InProc mode relies on the ASP.NET process. When the IIS process crashes or is restarted, the session state saved in the process will be lost.
3. StateServer mode
StateServer mode stores session data in a separate memory buffer, which is driven by a Windows service "ASP. NET State Service" (needs to be turned on in the windows service) to control this buffer, you need to set stateConnectionString:
When using the StateServer mode, all classes that need to be saved in the Session must be serializable:
[Serializable]
public class SomeClass { }
The advantage of the StateServer mode is that it is independent of the IIS process, and the restart of the IIS application does not affect the session data.
4. SQLServer mode
Use SQL Server to save the Session. Even if IIS is restarted, the Session will not be lost. You need to create the ASPState database first. Specific methods can be found online.
The above is the entire content of this article. I hope it will be helpful to everyone’s study. I also hope that everyone will support Script House.
The above is the detailed content of Share the problems and solutions encountered when publishing two ASP.NET websites. For more information, please follow other related articles on the PHP Chinese website!