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 ...

Source: Internet
Author: User
Tags httpcontext

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 ...

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.