简易聊天室:
protectedvoidPage_Load(objectsender,EventArgse)
{
Labelsay=newLabel();
say.Text=Application["content"].ToString();
this.Panel1.Controls.Add(say);
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
stringa=null;
a=Request["names"];
Application["content"]=Application["content"]+a+"\n"+"说:"+"<imgsrc='image/"+DropDownList1.SelectedValue+".gif'>"+this.TextBox1.Text+"<br/>";
}
站点计数器:
protectedvoidPage_Load(objectsender,EventArgse)
{
intnums=(int)Application["nums"];
nums++;
Application.Lock();
Application["nums"]=nums;
intsum=0;
Labella=newLabel();
do
{
sum=nums%10;
Application["content"]="<imgsrc='image/"+sum.ToString()+".png'/>";
nums=nums/10;
la.Text=Application["content"].ToStrin
g()+la.Text;
}while(nums!=0);//显示数字图片
this.Panel1.Controls.Add(la);
Application.UnLock();
}
Session对象和Cookies对象
if(this.TextBox1.Text.Trim()!="张三"|this.TextBox2.Text!="asdf")
{
Response.Write("输入有误!");
}
else
{
HttpCookiecookie=newHttpCookie("username",this.TextBox1.Text);
//利用Cookie实现自动欢迎信息(一次登陆之后,以后每次登陆自动获取原来的登陆信//息)
cookie.Expires=DateTime.Now.AddHours(1);
this.Response.Cookies.Add(cookie);
Session["username"]=this.TextBox1.Text;
Response.Redirect("Default2.aspx");
}
//实现网络安全性
if(Session["username"]==null)
this.Response.Redirect("default.aspx",true);
this.Literal1.Text=this.Session["username"].ToString();
this.Literal1.Text="欢迎你"+Session["username"];//通过Session对象传递信息