为什么我会在回发时收到Session [“Time”]变量的空引用异常,即使我已经在get请求中初始化了它。会话变量的空引用异常
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:未将对象引用设置为对象的实例。
这里没有错误... – clamchoda 2013-05-12 03:57:25
它是你的完整代码吗? – Arshad 2013-05-12 04:02:15
检查以下任一条件:http://support.microsoft.com/kb/306996 – 2013-05-12 04:02:15