Today, after you deploy the Web site on IIS, the following error occurs:
Session state can only be used if EnableSessionState is set to true in the configuration file or Page directive. Also make sure that you include the System.Web.SessionStateMod or custom session state module in the <system.web>
This code in the Web user space, the beginning, the best solution, because in the visual Sutio 2008 debugging when there is no such problem, so after Baidu, some said to change the Web. config
<sessionstate mode= "StateServer" sqlconnectionstring= "Data source=.;i ntegrated Security=sspi "timeout=" 1440 "/>
But after the change, or there is no effect, and some said that re-establish the project, the document one by one re-copied into, you can finally still no use.
Think of the previous use of this control, no fault ah, this problem puzzled a lot, one day, suddenly think of is not the question of the session, so, this defines the session:
HttpContext context = HttpContext.Current;
Then, use:
if (context. session["User"]! = null) {}
After the prompt:
This is the wrong change, is the question of the session, and suddenly thought will be with me before using the URLRewriter.dll page pseudo-static related?
Baidu a bit, changed the next Web. config was useful.
<system.webserver><modules runallmanagedmodulesforallrequests= "true" ></modules>
Find the following reason:
Session is empty, the program is not abnormal, then the problem is to do pseudo-static URL rewrite. IIS determines that a pseudo-static page request does not meet the default operating conditions for this configuration section of the session: Managedhandler, which means that IIS considers the request to only request a static file. Static files using the session is sure to be wrong.
At this point, the Web page is working properly.
Https://www.cnblogs.com/zyj649261718/p/4110429.html
After you deploy the ASP. NET Web site, you are prompted to use session state only if you set EnableSessionState to true in the configuration file or the Page directive ...