ASP.net Problem Session

Session state can only be used when enableSessionState is set to true

Today i was working with a sharepoint visual webpart and was trying to add some data in to session and was getting the error : {System.Web.HttpException: 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.
at System.Web.UI.Page.get_Session()
at inc_coe_forms.ContactUs.ContactUsUserControl.btnAddMoreFiles_Click(Object sender, EventArgs e)}

Or

Unexpected error occurred: System.Web.HttpException: 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 \\ section in the application configuration.
Solution

Usually Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive.

configuration file

1
2
3
4
<pages enableSessionState="true" >
<httpModules>
 <add type="System.Web.SessionState.SessionStateModule" name="Session" />
 </httpModules>

Page directive

1
<%@ Page Language="C#" enableSessionState="true"%>

This happens when IIS is not configured properly after creating SharePoint application and there are web parts or features that use session you may get the above error.

You can enable the session state in IIS when you followed step as below:


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: