Saturday, July 11, 2009

Enabling SessionState in ASP.Net Web Application

ASP.Net Error Message:
Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the configuration/system.web/httpModules section in the application configuration. (Somehow I'm not able to put <> signs below, please read [] as <>)

Solution 1:
Please confirm if enableSessionState is set to True in web.config file under section
[system.web]
[pages enableSesstionState = "True"]
[/system.web]

Solution 2:
In case if you had implemented AJAX, please confirm along with above setting you have following:

[httpModules]
[add name="Session" type="System.Web.SessionState.SessionStateModule"]
[/httpModules]

Solution 3:
If you see it is set correctly in web.config, confirm that in your desired ASPX page in Page Directive, you have not mistakenly written enableSessionState = "False".

Solution 4:
a. Go to IIS and Right Click the Virtual Directory of your application to open the Virtual Directory Properties.
b. In Virtual Directory Tab Click the Configuration button.
c. This will show the Application Configuration, select the Options tab.
d. Confirm, if Enable Session State checkbox is checked.

Solution 5:
In your web application if are using the inheritted Page class for all your aspx code behind files (For example public class BasePage : Syste.Web.UI.Page); you need to confirm one thing for sure that you have not called the child constructor before the System.Web.UI.Page constructor. This that session object is not created yet. Better way of using the Session in BasePage class is to override the OnLoad event and this shall work fine.

No comments:

Post a Comment