爲什麼我會在回發時收到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