广告
返回顶部
首页 > 资讯 > 后端开发 > ASP.NET >ASP.net(C#)实现简易聊天室功能
  • 396
分享到

ASP.net(C#)实现简易聊天室功能

2024-04-02 19:04:59 396人浏览 八月长安
摘要

本文实例为大家分享了asp.net(C#)实现简易聊天室功能的具体代码,供大家参考,具体内容如下 1.搭建框架 <html > <head>     <

本文实例为大家分享了asp.net(C#)实现简易聊天室功能的具体代码,供大家参考,具体内容如下

1.搭建框架

<html >
<head>
    <title>聊天系统</title>
</head>
    <frameset rows="80%,20%" >
          <frameset cols="20%,80%">
          <frame src="ReGISter.aspx" />
               <frame src="main.aspx" /> 
                     </frameset>
               <frame src="login.aspx"/>

      </frameset>

<body >
 
</body>
</html>

2.框架涉及三个页面  

建立相应的页面布局:

1.login.asp

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.WEB;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class login : System.Web.UI.Page
{undefined
    protected void Page_Load(object sender, EventArgs e)
    {undefined

    }
    protected void LoginBtn_Click(object sender, EventArgs e)
    {undefined
        if (LoginID.Text.Trim() == string.Empty)
        {undefined
            Response.Write("<script>alert('请输入用户名!')</script>");
            return;
        }
        if (LoginPwd.Text!= "123456")
        {undefined
            Response.Write("<script>alert('密码不正确,请重新输入')</script>");
            return;
        }
        if (!IfLonined())
        {undefined
            Response.Write("<script>alert('用户名已经存在')</script>");
            return;
        }
        Session["username"] = LoginID.Text;
        if (Application["user"] == null)
        {undefined
            Application["user"] = Session["username"];
        }
        else {undefined
            Application["user"] += "," + Session["username"];

        }
        Response.Redirect("send.aspx");

    }
    protected bool IfLonined()
    {undefined
        Application.Lock();
        string users;
        string[]user;
        if (Application["user"]!=null)
        {undefined
            users = Application["user"].ToString();
            user = users.Split(',');
            foreach(string s in user)
            {undefined
                if(s==LoginID.Text.Trim().ToString())
                {undefined
                    return false;
                }
            }
        }
        Application.UnLock();
        return true;
    }
    protected void LoginPWD_TextChanged(object sender, EventArgs e)
    {undefined

}
}

2.Register.asp

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Register : System.Web.UI.Page
{undefined
    protected ArrayList ItemList = new ArrayList();
    protected void Page_Load(object sender, EventArgs e)
    {undefined
        Response.AddHeader("Refresh", "1");
        Application.Lock();
        string users;
        string[] user;
        if (Application["user"]!=null)
        {undefined
            users = Application["user"].ToString();
            user = users.Split(',');
            for(int i=user.Length-1;i>=0;i--)
            {undefined
                ItemList.Add(user[i].ToString());

            }
            UserList.DataSource = ItemList;
            UserList.DataBind();
        }
        Application.UnLock();
    }
    protected void UserList_SelectedIndexChanged(object sender, EventArgs e)
    {undefined

    }
}

3.send.asp

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class send : System.Web.UI.Page
{undefined
    protected void Page_Load(object sender, EventArgs e)
    {undefined
        if (Session["username"] != null)
        {undefined
            Username.Text = Session["username"].ToString() + "说:";
        }
        else
        {undefined
            Response.Redirect("login.aspx");
        }


    }
    protected void SendBtn_Click(object sender, EventArgs e)
    {undefined
        string message;
        message = "<font color='blue'>" + Session["username"].ToString() + "</font>说:";
        message += Message.Text;
        message += "(<i>" + DateTime.Now.ToString() + "</i>)";
        message += "<br>";
        Application.Lock();
        if (chk.Checked)
            Application["chatcontent"] = (string)Application["chatcontent"] + message + "<img src=image/00.gif>" + "<img src=image/01.gif>";
        else
            Application["chatcontent"] = (string)Application["chatcontent"] + message;
      
        Application.UnLock();
        Message.Text = null;
    }
    protected void LoginBtn_Click(object sender, EventArgs e)
    {undefined
        Response.Redirect("login.aspx");
    }
    protected void LoginOutBtn_Click(object sender, EventArgs e)
    {undefined
        Application.Lock();
        if (Application["user"] != null)
        {undefined
            string users;
            string[] user;
            users = Application["user"].ToString();
            Application["user"] = null;
            user = users.Split(',');
            foreach (string s in user)
            {undefined
                if (s != Session["username"].ToString())
                {undefined
                    if (Application["user"] == null)
                    {undefined
                        Application["user"] = s;
                    }

                    else
                    {undefined
                        Application["uesr"] = Application["user"] + "," + s;
                    }
                }
            }
        }
        if (Session["username"] != null)
        {undefined
            Session["username"] = null;
        }
        Application.UnLock();
        Response.Redirect("login.aspx");


    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {undefined

    }

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: ASP.net(C#)实现简易聊天室功能

本文链接: https://www.lsjlt.com/news/138958.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • ASP.net(C#)实现简易聊天室功能
    本文实例为大家分享了ASP.net(C#)实现简易聊天室功能的具体代码,供大家参考,具体内容如下 1.搭建框架 <html > <head>     <...
    99+
    2022-11-13
  • node+socket实现简易聊天室功能
    本文实例为大家分享了node+socket实现简易聊天室的具体代码,供大家参考,具体内容如下 服务端 const net = require('net') const serv...
    99+
    2022-11-12
  • C#实现简易多人聊天室
    本文实例为大家分享了C#实现简易多人聊天室的具体代码,供大家参考,具体内容如下 只有一个群聊的功能 服务端 using System; using System.Collectio...
    99+
    2022-11-13
  • Nodejs实现多房间简易聊天室功能
    1、前端界面代码   前端不是重点,够用就行,下面是前端界面,具体代码可到github下载。 2、服务器端搭建   本服务器需要提供两个功能:http服务和websocket服务,由于node的事件驱动机制...
    99+
    2022-06-04
    简易 聊天室 房间
  • C++实现简易UDP网络聊天室
    本文实例为大家分享了C++实现简易UDP网络聊天室的具体代码,供大家参考,具体内容如下 工程名:NetSrv NetSrv.cpp //服务器端 #include<Wins...
    99+
    2022-11-12
  • C语言实现简易网络聊天室
    本文实例为大家分享了C语言实现网络聊天室的具体代码,供大家参考,具体内容如下 业务逻辑: 1、客户端注册名字 2、告诉所有在线的客户端,XXX进入聊天室 3、新建一个线程为该客户端服...
    99+
    2022-11-12
  • Java Socket实现简易聊天室
    Java-Socket编程实现简易聊天室(TCP),供大家参考,具体内容如下 实现一个服务器接收多个客户端 测试: 首先启动服务器,然后启动三个客户端,输入三个不同的用户名,分别在聊...
    99+
    2022-11-11
  • C#基于Socket实现简单聊天室功能
    因为这段时间在学习Socket,所以就试着写了一个简单的聊天室。主要分为服务器端和多个客户端。利用服务器端作数据中转站,实现消息群发。 1、服务器端有两个类: using Syste...
    99+
    2022-11-13
  • C语言实现简单的聊天室功能
    用C语言实现简单的聊天室功能,供大家参考,具体内容如下 服务器端 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> ...
    99+
    2022-11-12
  • C++如何实现简易UDP网络聊天室
    小编给大家分享一下C++如何实现简易UDP网络聊天室,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!工程名:NetSrvNetSrv.cpp//服务器端#inclu...
    99+
    2023-06-20
  • JAVANIO实现简单聊天室功能
    本文实例为大家分享了JAVA NIO实现简单聊天室功能的具体代码,供大家参考,具体内容如下 服务端 初始化一个ServerSocketChannel,绑定端口,然后使用Selecto...
    99+
    2022-11-12
  • java实现简易聊天功能
    本文实例为大家分享了java实现简易聊天功能的具体代码,供大家参考,具体内容如下 应用客户端和服务端通过控制台的输入输出实现简易聊天功能 思路: 1.创建服务端类ChatServer...
    99+
    2022-11-13
  • Java实现简单的聊天室功能
    本文实例为大家分享了Java实现简单聊天室功能的具体代码,供大家参考,具体内容如下 一、客户端的创建 1.我们可以用Socket来创建客户端 public class Client...
    99+
    2022-11-13
  • python实现简易聊天室(Linux终端)
    本文实例为大家分享了python实现简易聊天室的具体代码,供大家参考,具体内容如下 群聊聊天室 1.功能:类似qq群聊功能 有人进入聊天室需要输入姓名,姓名不能重复 有人进入聊天室,其他人会受到通知 xxx进入...
    99+
    2022-06-02
    python 聊天室
  • 如何用python实现简易聊天室
    本篇内容主要讲解“如何用python实现简易聊天室”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何用python实现简易聊天室”吧!1.功能:类似qq群聊功能有人进入聊天室需要输入姓名,姓名不...
    99+
    2023-06-20
  • Java Socket怎样实现简易聊天室
    这篇文章主要介绍了Java Socket怎样实现简易聊天室,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。Java-Socket编程实现简易聊天室(TCP),具体内容如下实现一...
    99+
    2023-06-14
  • 基于C++实现TCP聊天室功能
    本文实例为大家分享了C++实现TCP聊天室功能的具体代码,供大家参考,具体内容如下 TCPServer.cpp: // TCPServer.cpp : Defines the ...
    99+
    2022-11-12
  • C#使用WebSocket实现聊天室功能
    WebSocket介绍 WebSocket是HTML5开始提供的一种在单个 TCP 连接上进行全双工通讯的协议。 在WebSocket API中,浏览器和服务器只需要做一个握手的动作...
    99+
    2022-11-13
  • C#基于WebSocket实现聊天室功能
    本文实例为大家分享了C#基于WebSocket实现聊天室功能的具体代码,供大家参考,具体内容如下 前面两篇温习了,C# Socket内容 本章根据Socket异步聊天室修改成WebS...
    99+
    2022-11-13
  • C++实现Window环境聊天室功能
    C++ Window环境聊天室,供大家参考,具体内容如下 最近闲来无事,想学习一下C++的并发编程和Socket信息传输,故以聊天室为载体进行学习。话不多说,代码开干。 聊天室分为多...
    99+
    2022-11-12
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作