会话变量在 Chrome、Firefox 中工作但在 IE11 中失败

Session Variables Work in Chrome, Firefox but Fail in IE11

我们最近将网络服务器升级到 Win2012(从 2008 年开始)并开始使用 ActiveDirectory。主网站使用用 C# (ASP.NET 2.0) 编写的外部订购表。在我们迁移之前,旧服务器上的一切都运行良好。现在我在 IE 11 中尝试读取会话变量时遇到错误(其他浏览器一切正常)。

这是我在导致它的行中遇到的错误:

Server Error in '/' Application.

Object reference not set to an instance of an object. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 



Line 974:  private void WriteTextConfirmation ()
Line 975:  {
Line 976:    string sFolders_OrderForm = Session ["Folders_OrderForm"].ToString ();
Line 977:    string sOrderNumber = Session ["OrderNumber"].ToString ();
Line 978:

源文件:d:\Web Sites\Order Form\SubmitOrder.aspx.cs 行:976

堆栈跟踪:

[NullReferenceException: Object reference not set to an instance of an object.]
   SubmitOrder.WriteTextConfirmation() in d:\Web Sites\Order Form\SubmitOrder.aspx.cs:976
   SubmitOrder.Page_Load(Object sender, EventArgs e) in d:\Web Sites\Order Form\SubmitOrder.aspx.cs:1189
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +24
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +41
   System.Web.UI.Control.OnLoad(EventArgs e) +131
   System.Web.UI.Control.LoadRecursive() +65
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2427

问题是正在读取的会话变量为空。它们应该在默认表单中设置并传递以供在 SubmitOrder 表单中使用。这些变量适用于 FireFox 和 Chrome 但在 IE 中失败。我不确定为什么会这样。

既然你说它是特定于浏览器的,那么它必须是浏览器的设置。也许您关闭了 cookies?

更新 我查了下,好像还是跟cookie有关。

Session variable empty in iis7 application

Another common cause of this issue is when the server name contains underscores (e.g. DEV_TEST). Underscores aren't allowed as host names, and could interfere with the ability to set cookies.

这个服务器故障问题有几个答案说的是同一件事: https://serverfault.com/questions/178733/iis-7-0-does-not-keep-session-variables

另一个 SO 问题说下划线:: IE8 does not keep Session Variables

来自 Google 的更多内容:https://www.google.com/search?q=iis+application+session+variables+IE

我们遇到了同样的问题,在 Web.config 中将会话状态设置为无 cookie 解决了我们的问题。