这是个我在网上找的小程序,输入用户名,进入,直接就可以聊天了,但是几个人一起怎么测试呢??求助各位大侠!!
代码:
chatmain:
<%@ Page language="c#" Inherits="charroom.ChatMain" CodeFile="chatmain.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
姓名:<input type=text name=username />
<input type=submit  value=提交 name =submit/>
</form>
</body>
</HTML>
chatmain.cs:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace charroom
{
public partial class ChatMain : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
if(Page.IsPostBack && Request.Form.Get("username")!="" )
{
Session["username"]=Request["username"];
Application["message"]="";
Response.Redirect("chatRoom.html");
}
else
{
Response.Write("<font size=10 color=red>请输入用户名</font>");
}
}        }
}
send:
<%@ Page language="c#" Inherits="charroom.SendMain" CodeFile="send.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>

</head>
<body>
<form id="Form1" method="post" runat="server">
消息:<input type=text size=10 name="sendMessage" />

<input type=submit name=submit value="发送" />
</form>
</body>
</html>
send.cs:
namespace charroom
{ public partial class SendMain : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
try
{
string talk=Request["sendMessage"];
string message1=Application["message"].ToString()+Session["username"].ToString()+"说:"+talk+"<br>";
Application.Lock();
Application["message"]=message1;
Application.UnLock();
}
catch
{
Response.Write("你还没有登录,请先<a href='chatmain.aspx'>登录</a>");
}
}
        }
}
display:
<%@ Page language="c#" Inherits="charroom.display" CodeFile="display.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>display</title>
<meta http-equiv="REFRESH" content="5,display.aspx">
</HEAD>
</HTML>
display.cs:
namespace charroom
{ public partial class display : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
Response.Write(Application["message"]);
}         }
}