【发布时间】:2015-01-07 10:02:32
【问题描述】:
我有一个在 x64 机器上的 IIS 7 上运行的 ASP.NET v4.0 Web 应用程序。 这个应用程序在本地开发机器上没有问题,在以前的 x86 服务器上没有问题。
现在的问题是回发后所有会话变量都为空。例如。我有一个自动回发的下拉列表。我一直在尝试解决这个问题几个小时,但没有任何运气。有人有什么想法吗?
SessionState 是 inProc,我没有在应用程序池上启用 webGarden。
我用下面的代码做了一个测试。单击后,如果我在新服务器上运行程序,则输出显示 null。但是如果我在本地运行它,它会按预期显示 -4
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="xyz.aspx.cs" Inherits="WebApplication1._default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="jsFunctions.js" ></script>
<link rel="stylesheet" type="text/css" media="screen" href="css1.css"/>
<link rel="stylesheet" type="text/css" media="print" href="css1_print.css" />
</head>
<body class="daBody" onload="HideCalendar('divCalendar')">
<form id="form1" runat="server">
<asp:TextBox ID="output" runat="server" CssClass="output1"></asp:TextBox>
<asp:Button ID="b1" runat="server" OnClick="b1Click" BorderWidth="50px" />
</form>
</body>
</html>
namespace WebApplication1
{
public partial class _default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MaintainScrollPositionOnPostBack = true;
if (!IsPostBack)
{
Session["test"] = -5;
output.Text = ""+(int)Session["test"];
}
}
protected void b1Click(object sender, EventArgs e)
{
if(Session["test"] == null)
output.Text = "null";
else
Session["test"] = ""+((int)Session["test"]+1);
}
}
}
所以感觉好像我错过了一个配置步骤。
【问题讨论】:
-
Session[test] 或 Session["test"] ?
-
会话[“测试”]。进行了编辑
-
还有
Session[test]s。您显示的代码将在第二次单击按钮时引发转换异常。 -
实际上它不会抛出它,因为 Session["test"] 为空
-
我将从查看 cookie 开始。 Cookie 用于跟踪会话。服务器和/或浏览器中是否存在阻止使用 cookie 的配置?
标签: asp.net iis-7 postback session-variables