【发布时间】:2014-02-05 21:52:28
【问题描述】:
我已经苦苦挣扎了一个星期了,我找不到解决问题的方法。我对 Sharepoint 还很陌生,想创建一个简单的 webpart。
为此,我需要一个 Session 来存储我的 DataTable,其中包含来自数据库的数据。
例如:
private void storeDataTable(DataTable dt)
{
Session["dtSession"] = dt;
}
当我在调试这段代码时,抛出了一个异常:
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
到目前为止我做了什么来解决这个问题:
-
尝试在我的 ascx.cs 中启用 SessionState - 标记
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyWebPart.ascx.cs" Inherits="MyWebPart.VisualWebPart.VisualWebPartUserControl" %> <%@ Page EnableSessionState="true" %>当我运行这个时,我遇到了一个异常:
server tag is not well formed. -
在“C:\inetpub\wwwroot\wss\VirtualDirectories\80\web.config”下的 web.config 中添加以下内容
<pages enableSessionState="true" enableViewState="true" enableViewStateMac="true">和
<httpModules> <add name="Session" type="System.Web.SessionState.SessionStateModule" /> </httpModules>3.在 SharePoint 2010 命令行管理程序中运行以下命令:
Enable-SPSessionStateService –DefaultProvision4.激活services.msc下的ASP.NET State服务,将start改为auto。
这些步骤都不能解决我的问题。
【问题讨论】:
-
没有,但据我所知,我只需要默认的 In-Proc-Mode 吗?我已按照本指南启用 SessionState:nikpatel.net/2012/02/12/…
-
InProc 模式仅在您有一个 WFE 或者您在负载均衡器上配置了持久性的情况下才有效。如果您的应用程序可能需要扩展到一台服务器之外,那么限制自己是一个糟糕的设计决策。
-
感谢您的回复,但我不得不问:是InProc模式的原因,为什么无法启用SessionState?如果我的应用程序没有任何机会需要更多的服务器资源怎么办?
-
不,inProc 模式是默认模式,通常不会产生任何问题。但是,您的 webpart 是否集成在其他控件中?
标签: c# asp.net sharepoint-2010 session-state