注册 登录
编程论坛 ASP.NET技术论坛

.net聊天室

浅浅。微笑 发布于 2011-11-26 19:13, 1033 次点击
刚学没多久的.net,遇到用Application制作聊天室,不会...  
建立了3个web主页,一个为聊天室的主页面,一个用来显示用户的聊天信息,
最后一个显示在线用户的列表。  可是都建完之后 三个之间都是独立的,
没有办法连接。
我汗 ,希望有高人指点,尽量详细点,我是初学者。。。。
主要的
<script runat="server">

    void Application_Start(object sender, EventArgs e)
    {
        // 在应用程序启动时运行的代码
        string user = "";
        Application["user"] = user;
        Application["username"] = 0;
        string chats = "";
        Application["chats"] = chats;
        Application["current"] = 0;
    }
   



 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["chats"] = P_int_current;
        Application.UnLock();
    }





  protected void Page_Load(object sender, EventArgs e)
    {
        int P_int_current=Convert.ToInt32(Application["current"]);
        Application.Lock();
        string P_str_chats = Application["chats"].ToString();
        string[] P_str_chat = P_str_chats.Split(',');
        for (int i = P_str_chat.Length - 1; i >= 0; i--)
        {
            if (P_int_current == 0)
            {
                txtContent.Text = P_str_chat[i].ToString();

            }
            else
            {
                txtContent.Text = txtContent.Text + P_str_chat[i].ToString();
            }
        }
        Application.UnLock();
    }
3 回复
#2
浅浅。微笑2011-11-26 19:15
顶一下
#3
zhouhouyang012011-12-01 18:45
我可以给你个简单的例子! 想要的话给我说一声!
#4
sandyhaidong2011-12-14 16:28
顶一下
1