System.Web.SessionState.HttpSessionState.this[string].get未将对象引用设置到对象的实例

https://www.yljianzhan.com/安装了个聊天小程序,用visual studio 2017测试运行后,显示错误:

未将对象引用设置到对象的实例。

本人初学,什么语法也不懂!! 谁要这些小网站程序块,联系我!qq:466074134 

原主页聊天代码:(https://yljianzhan.com,

using System;
using System.Data;
using System.Configuration;
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;
using System.Web.SessionState;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        int P_int_current = Convert.ToInt32(Application["current"]);
        Application.Lock();
        if (P_int_current == 0 || P_int_current > 20)
        {
            P_int_current = 0;
            Application["chats"] = Session["userName"].ToString() + "说:" + txtMessage.Text.Trim() + "(" + DateTime.Now.ToString() + ")";
        }
        else
        {
            Application["chats"] = Application["chats"].ToString() + "," + Session["userName"].ToString() + "说:" + txtMessage.Text.Trim() + "(" + DateTime.Now.ToString() + ")";
        }
        P_int_current += 1;
        Application["current"] = P_int_current;
        Application.UnLock();
    }
    protected void btnExit_Click(object sender, EventArgs e)
    {

        Application.Lock();
        string P_str_userName = Application["user"].ToString();
        Application["user"] = P_str_userName.Replace(Session["userName"].ToString(), "");
        Application.UnLock();
        Response.Write("<script>window.opener=null;window.close();</script>");
    }
}
以下是运行后错误显示:

“/”应用程序中的服务器错误。
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误: 


行 28:         {
行 29:             P_int_current = 0;
行 30:             Application["chats"] = Session["userName"].ToString() + "说:" + txtMessage.Text.Trim() + "(" + DateTime.Now.ToString() + ")";
行 31:         }
行 32:         else

源文件: c:\Users\Administrator\source\repos\07\Default.aspx.cs    行: 30 

堆栈跟踪: 


[NullReferenceException: 未将对象引用设置到对象的实例。]
   _Default.btnSend_Click(Object sender, EventArgs e) in c:\Users\Administrator\source\repos\07\Default.aspx.cs:30
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9782354
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +204
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639

版本信息: Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.7.3190.0

QQ:46607414
————————————————
版权声明:本文为CSDN博主「anyong2016」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/anyong2016/article/details/104349694

发布了7 篇原创文章 · 获赞 2 · 访问量 4237

猜你喜欢

转载自blog.csdn.net/anyong2016/article/details/104327367