当前位置:编程学习 > C#/ASP.NET >>

提问!回答!

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
       
        if (Session["username"].ToString() =="游客")---------未将对象引用设置到对象的实例这是为什么!!!
        {

            Response.Redirect("../login/login.aspx");
        }
        else
        {
            Response.Redirect("../member borrow message/bwme.aspx");
        
        }
    } --------------------编程问答--------------------  if (Session["username"] != null){
     if(Session["username"].ToStrong()=="游客" ){
          //do sth....
     }
 }

 先判断是否空 在使用

--------------------编程问答--------------------
引用 1 楼 ju523756055 的回复:
if (Session["username"] != null){
  if(Session["username"].ToStrong()=="游客" ){
  //do sth....
  }
 }

 先判断是否空 在使用

=============
非常支持 --------------------编程问答--------------------
引用 1 楼 ju523756055 的回复:
 if (Session["username"] != null){
     if(Session["username"].ToStrong()=="游客" ){
          //do sth....
     }
 }

 先判断是否空 在使用


++ --------------------编程问答--------------------  if (Session["username"]==null || Session["username"].ToString() =="游客")
{
   Response.Redirect("../login/login.aspx");
   return;
}
Response.Redirect("../member borrow message/bwme.aspx");
return; --------------------编程问答-------------------- 为空的那个session丢失了或根本就不存在呗 --------------------编程问答-------------------- 直接把.toString(),就不会报错了,不过会有空的情况,要不就是先判断是否为空。感觉先判空还是好点。 --------------------编程问答-------------------- session["username"]=null了呗 --------------------编程问答-------------------- if(session["username"]!=null)
{
执行
} --------------------编程问答--------------------
引用 1 楼 ju523756055 的回复:
if (Session["username"] != null){
  if(Session["username"].ToStrong()=="游客" ){
  //do sth....
  }
 }

 先判断是否空 在使用
--------------------编程问答--------------------
引用楼主 z631373000 的回复:
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  {
   
  if (Session["username"].ToString() =="游客")---------未将对象引用设置到对象的实例这是为什么!!!
  {

  Response.Redirect("../login/log……

++++ --------------------编程问答--------------------
引用 1 楼 ju523756055 的回复:
if (Session["username"] != null){
  if(Session["username"].ToStrong()=="游客" ){
  //do sth....
  }
 }

 先判断是否空 在使用

上面弄错了 --------------------编程问答-------------------- Session["username"]没找到对象 --------------------编程问答-------------------- [Quote=引用 11 楼 qiqittjj 的回复:]

引用 1 楼 ju523756055 的回复:
if (Session["username"] != null){
if(Session["username"].ToStrong()=="游客" ){
//do sth....
}
}

+1
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,