look out! Those pits when asp.net website is published

Time:2021-11-28

Development tools: VS2010, mvc4.0, sqlserver2008

Server: Windows Server 2012, iis8, sqlserver2012

One is too laggy for every page to be opened, and 50 seconds or longer, and second times to open.

Estimated cause: the compilation speed is slow, but there is no such card for publishing on machines with vs environment

terms of settlement:

Use a higher version of VS, “precompile during release”; Use the application initialization function of iis8. 1. Use vs2017 “precompile during release”

An error was encountered while publishing:

It is an error to use a section registered as allowdefinition =’machinetoapplication ‘outside the application level. This error may be caused if the virtual directory is not configured as an application in IIS.

terms of settlement:Comment the following code in web.config at publish time


<!--<authentication mode="Forms">
 <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>-->

2. Use the application initialization function of iis8

Solution to slow first visit of asp.net website

2、 Frequent loss of asp.net session

Problem phenomenon: 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 mode is “InProc mode” and changed to “stateserver mode”. The problem is solved.

1. Off mode

The session is closed.

The following can be written in the < system. Web > section of the web. Config file:

<sessionState mode=”off”>

To close a session on a page, add:

<%@ Page EnableSessionState=”false” %>

2. InProc mode (default mode)

If the 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 to the web.config file, for example:

<sessionState mode=”InProc” cookieless=”false” timeout=”20″ />

Cookie less sets whether cookies are allowed to be used. Timeout sets the timeout, in minutes.

InProc mode depends on the asp.net process. When the IIS process crashes or restarts, the session state saved in the process will be lost.

3. Stateserver mode

Stateserver mode is to store session data in a separate memory buffer, which is controlled by a Windows service “asp.net state service” (which needs to be enabled in Windows Service). Stateconnectionstring needs to be set:

<sessionState mode=”StateServer”  stateConnectionString=”tcpip=127.0.0.1:42424″ timeout=”20″ />

When using stateserver mode, all classes that need to be saved in session should be added with serializable features:

[Serializable]
public class SomeClass { }

The advantage of stateserver mode is that it is independent of IIS process, and the restart of IIS application does not affect session data.

4. SQL Server Mode

Use SQL server to save the session. Even if IIS restarts, the session will not be lost. You need to create the ASPState database first. Specific methods can be queried online.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support developpaer.