“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 20: {
行 21:
行 22: if (Session["logon"].ToString() != "logonSuccess")行 23: Response.Redirect("logon.aspx");
行 24:
源文件: C:\wwwroot\Session\Session\index.aspx.cs 行: 22 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
Session.index.Page_Load(Object sender, EventArgs e) in C:\wwwroot\Session\Session\index.aspx.cs:22
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
请问此错误怎么解决?
这是书上的一个例子,就是使用SESSION来保存客户信息的。
错误说是未将对象引用设置到对象的实例。 在红色的那行出错,我看了下代码,好像没有新建SESSION对象,怎么对SESSION对象初始化呢?
--------------------------------------------------------------------------------未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 20: {
行 21:
行 22: if (Session["logon"].ToString() != "logonSuccess")行 23: Response.Redirect("logon.aspx");
行 24:
源文件: C:\wwwroot\Session\Session\index.aspx.cs 行: 22 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
Session.index.Page_Load(Object sender, EventArgs e) in C:\wwwroot\Session\Session\index.aspx.cs:22
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
请问此错误怎么解决?
这是书上的一个例子,就是使用SESSION来保存客户信息的。
错误说是未将对象引用设置到对象的实例。 在红色的那行出错,我看了下代码,好像没有新建SESSION对象,怎么对SESSION对象初始化呢?
解决方案 »
- ASP.NET 删除word中的图片
- 怎样将已写入dataset中table的某个列的不重复值,作为依据,再次到数据库进行查询?
- 薪酬计算公式问题?烦~烦~烦~烦~烦~烦~烦~烦~烦~烦~烦~
- 高手帮忙,如何在GRIDVIEW里删除DATASET的一行数据,急~~
- 如何使用GridView显示条件查询的结果!
- 用datagrid 检索出来的图片如何排版
- 求助,如何把数字转换成大写
- 只要进来就能。。。。。。。
- 分页里面选择“AllowCustomPaging”属性以后怎么不能分页了?我用的是 C#,下面是该页的代码页面
- 在asp.net中怎样提交页面
- 关于单击textbox控件,即产生数据的问题
- 有没有人听说过悦商网
可以写成
if(Session["logon"] !=null & Session["logon"].ToString()!="logonSuccess")
if (Session["logon"] != null)
{
if (Session["logon"].ToString() != "logonSuccess")
....
}
{
get
{
if (Session["LoginOk"] != null && (bool)Session["LoginOk"])
{
return true;
}
else
{
return false;
}
}
set
{
Session["LoginOk"] = value;
}
}
在登录验证成功时,可以这样写:
LoginOK = true;
然后在其他页面的Page_load中:
if (!loginOK)
{
Response.Redirect("logon.aspx");
}更多参考:
http://www.cnblogs.com/insus/articles/1429434.html
行 21:
行 22: if (Session["logon"] != null & Session["logon"].ToString() != "logonSuccess")
行 23: Response.Redirect("logon.aspx");
行 24:
源文件: C:\wwwroot\Session\Session\index.aspx.cs 行: 22 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
Session.index.Page_Load(Object sender, EventArgs e) in C:\wwwroot\Session\Session\index.aspx.cs:22
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
using System;
using System.Data;
using System.ComponentModel;
using System.Drawing;
using System.Web.SessionState;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;namespace Session
{
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ if (Session["logon"] != null & Session["logon"].ToString() != "logonSuccess")
Response.Redirect("logon.aspx");
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); } protected override void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
} }
}
using System;
using System.Data;
using System.ComponentModel;
using System.Drawing;
using System.Web.SessionState;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;namespace Session
{
public partial class logonForm : System.Web.UI.Page
{ protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox txtUserName;
protected System.Web.UI.WebControls.TextBox txtPassword;
protected System.Web.UI.WebControls.Button btnLogon;
protected void Page_Load(object sender, EventArgs e)
{
} private void InitializeComponent()
{
this.btnLogon.Click += new System.EventHandler(this.btnLogon_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
protected override void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
} private void btnLogon_Click(Object sender, System.EventArgs e)
{
if (txtUserName.Text == "user" && txtPassword.Text == "pass")
{
Session["logon"] = "logonSuccess";
Response.Redirect("index.aspx");
}
else
{
Session["logon"] = "logonFailed";
} } }}
session.add("名字",值(这个值就是名字的值))
你看下你的session添加的是否正确
会不会和这个有什么关系?
我并不知道在我建的这个项目里index.aspx和logon.aspx到底哪个是主页面
protected void Page_Load(object sender, EventArgs e)
{ if (Session["logon"] != null & Session["logon"].ToString() != "logonSuccess")
Response.Redirect("logon.aspx");
else
Response.Write("OK");
}
可还有个问题,为什么登陆成功后跳转到index.aspx页面时屏幕输出为OKOK
为什么输出了两次? 代码里只是Response.Write("OK");啊
我选中logon.aspx选项卡,再点开始运行就没问题了现在的问题就是那个OK为什么出现两次呢?
这个调试一下呀.看看Response.Write("OK"); 执行了几次