c# - 生产服务器上的 session 为空

标签 c# asp.net session

我的生产服务器出现了一个奇怪的异常:

来源错误:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

堆栈跟踪:

[NullReferenceException: Object reference not set to an instance of an object.] selectie.Functie..ctor() in ..\Page\Specificaties\Functie\Functie.cs:35 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +91 System.Web.UI.Control.LoadRecursive() +74 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

第 35 行:

Kast kast = (Kast)HttpContext.Current.Session["kast"];


该 session 用于多个网络方法,例如:

[WebMethod(EnableSession = true)]
public static String button_click(String information) {

}

[WebMethod(EnableSession=true)]
public static void ChangeKast(String id, String value)
{

}

在寻找解决方案时,我发现了这个:

As you might expect, if you enable session support for one Web method, that does not imply that it is enabled for another Web method. In fact, the Context.Session property will be null if EnableSession is not explicitly set to True for a particular Web method.

它在本地运行完美,从今天开始就一直在工作...我该如何解决这个问题?

最佳答案

<system.web> 下的live 机器上的Web.Config 中查看元素 那里应该有一个名为 <sessionstate> 的元素确保它没有设置为 Mode="Off"

<configuration>
...
<system.web>
....
<sessionState mode="InProc" cookieless="false" timeout="20" />
....
</system.web>
....
</configuration>

关于c# - 生产服务器上的 session 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7189558/

相关文章:

c# - 在 asp.net c# 4.0 中完全以编程方式创建 Gridview

java - 如何获取所有 session 值和名称?

PHP session 超时 htaccess 文件

python - Flask session 在蓝图中不持久

c# - 如何将文件的缩略图提取到 .NET 中的图像文件中?

c# - 友好的 URL 与丑陋的查询字符串 URL SharePoint、HTTPModule?

c# - headless (headless)模式下的 Firefox 以小尺寸运行(1366、768)

c# - 系统.Data.SqlClient.SqlException : 'Incorrect syntax near ' )'.' is that sql query error or something?

asp.net - 如何使用 MVC 3 启用/使用跨源资源共享?

javascript - 更新产品数量而不进行回发