1、环境:VS2019+C#+.NETFramework4.5
2、问题:在登陆界面把用户的信息赋值给Session:
Session["userId"] = dr["UserId"].ToString();
Session["username"] = dr["UserName"].ToString();
3、在框架网页里的Page_Load里用trycatchfinally对Session["userId"] 的值进行判断,如果失效为空,关闭框架网页跳转登录界面:
try
{
if (Session["userId"].ToString() == null)
{
}
}
catch
{
Response.Write("<script>alert('由于您长时间未进行操作,系统已为您自动退出登录!!!')</script>");
Response.Write("<script language=javascript>window.parent.opener=null;window.parent.open('','_self','');window.parent.close();window.open('../default.aspx');</script>");
}
user_id.Text = Session["userID"].ToString();
运行后当Session["userId"] 为空值时,逐条语句调试时,系统运行了二个Response.Write语句,但没出现提示和关闭框架网页跳转登录界面,停止在user_id.Text = Session["userID"].ToString();并提示:
System.NullReferenceException:“未将对象引用设置到对象的实例。”
请教:1、为什么运行了二个Response.Write语句,但没出现提示和关闭框架网页跳转登录界面;
2、这代码在VS2013+C#+.NETFramework2.0环境下可以正常运行,出现提示后关闭框架网页跳转登录界面。为什么在VS2019+C#+.NETFramework4.5环境下就出现问题,要如何修改才能正常?