【问题标题】:Enable SessionState Issue in ASP.NET and Sharepoint 2010在 ASP.NET 和 Sharepoint 2010 中启用 SessionState 问题
【发布时间】: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

到目前为止我做了什么来解决这个问题:

  1. 尝试在我的 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.
    
  2. 在“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 –DefaultProvision
    

    4.激活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


【解决方案1】:

我能够自己解决我的问题。我搜索了两个 web.configs(VirtualDirectories\80 和 VirtualDirectories\7099)并删除了一些条目。 现在我的 web.config 中有以下条目:

<httpModules>
     <remove name="Session" />
     <add name="Session" type="System.Web.SessionState.SessionStateModule" />
</httpModules>

 <pages enableSessionState="true" enableViewState="true" enableViewStateMac="true" enableEventValidation="true" etc...>

我想我的错是声明了另一个 SessionState,它是服装。我已经删除了这些条目,应用程序就像一个魅力。所以看起来,当声明了很多 Sessions 时,也会抛出异常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-25
    • 2015-12-06
    • 2012-05-30
    • 1970-01-01
    相关资源
    最近更新 更多