【发布时间】:2013-05-06 09:59:09
【问题描述】:
为什么即使我在 get 请求中初始化了 Session["Time"] 变量,我也会在此处得到一个空引用异常。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication4
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["Time"] = DateTime.Now.ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(Session["Time"].ToString());
}
}
}
异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例。
【问题讨论】:
-
这是你的完整代码吗?
-
检查以下任一条件:support.microsoft.com/kb/306996
-
此代码不应导致错误,除非存在配置问题。您可以发布会话管理的堆栈跟踪和 web.config 设置吗?
标签: asp.net