I've been struggling for a week now, I can't find a solution for my problem. I'm fairly new to Sharepoint and want to create a simple webpart.
For this, I need a Session where I can store my DataTable, which contains data from a database.
E.g.:
private void storeDataTable(DataTable dt)
{
Session["dtSession"] = dt;
}
When I'm debugging this code, an exception is thrown:
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
What I've done so far, to solve this issue:
Tried to enable SessionState in my ascx.cs - markup
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyWebPart.ascx.cs" Inherits="MyWebPart.VisualWebPart.VisualWebPartUserControl" %> <%@ Page EnableSessionState="true" %>
When I am running this, I got an exception:
server tag is not well formed.
Add following to the web.config under "C:\inetpub\wwwroot\wss\VirtualDirectories\80\web.config"
<pages enableSessionState="true" enableViewState="true" enableViewStateMac="true">
and
<httpModules> <add name="Session" type="System.Web.SessionState.SessionStateModule" /> </httpModules>
3.Run the following in the SharePoint 2010 Management Shell:
Enable-SPSessionStateService –DefaultProvision
4.Activate the ASP.NET State service under services.msc and change start to automatic.
None of this steps could resolve my issue.