Professional Documents
Culture Documents
Request 对象(客户端的请求信息)
Request 对象的常用属性和方法
Response 对象(Web 服务器对客户端请求的响应)
Response 对象的常用属性和方法
Cookie 对象(把少量数据储存到客户端的硬盘或内存中,或是从客户端硬盘读取数据的一
种技术)
Cookie 对象的常用属性和方法
Session 对象
Session 对象的常用属性和方法
Application 对象保存所有客户的信息
Application 对象的常用属性和方法
实现在线人数的统计
二、实验内容:
1、启动 Visual Studio 2010 执行“文件”“新建”“项目”命令,打开如图所示的“新建
项目”对话框。打开“Visual C#”类型节点,选择“Web”子节点这个模板,同时在右边窗
口中选择“ASP.NET 空 Web 应用程序”,在“名称”文本框中输入“任务 4.8.2”,并在
“位置”文本框中输人相应的存储路径。最后,单击“确定”按钮。
2、登录及注册功能实现代码见“任务 4.7”,这里不再赘述。
register.aspx:
<form id="form1" runat="server">
<table width="1200px" align="center" border="0"
<tr><td width="400px" class="auto-style2" align="right"> 用 户 姓 名 : </td><td
width="400px" class="auto-style2">
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
</td><td width="400px" class="auto-style2">
<asp:Button ID="jiance" runat="server" Text=" 检 测 是 否 可 用 "
OnClick="jiance_Click" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtUserName" ErrorMessage=" 用 户 名 不 能 为 空 "
ForeColor="Red"></asp:RequiredFieldValidator>
</td></tr>
<tr><td width="400px" align="right" class="auto-style5"> 密码:</td><td width="400px"
class="auto-style5">
<asp:TextBox ID="txtPwd" runat="server" TextMode="Password"></asp:TextBox>
</td><td width="400px" class="auto-style5">
<asp:RequiredFieldValidator ID="RequiredFieldValidatorPwd" runat="server"
ControlToValidate="txtPwd" ErrorMessage=" 密 码 不 能 为 空 "
ForeColor="Red"></asp:RequiredFieldValidator>
</td></tr>
<tr><td width="400px" align="right" class="auto-style4"> 确 认 密 码 : </td><td
width="400px" class="auto-style4">
<asp:TextBox ID="txtPwd2" runat="server" TextMode="Password"></asp:TextBox>
</td><td width="400px" class="auto-style4">
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="txtPwd" ControlToValidate="txtPwd2" ErrorMessage="两次输入的密码不
一致" ForeColor="Red"></asp:CompareValidator>
</td></tr>
</table>
</form>
Register.cs:
namespace User_Register
{
public partial class Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
UnobtrusiveValidationMode = new UnobtrusiveValidationMode();
if (this.txtPwd.Text != " ")
{
this.txtPwd.Attributes["value"] = this.txtPwd.Text;
}
if (this.txtPwd2.Text != " ")
{
this.txtPwd2.Attributes["value"] = this.txtPwd2.Text;
}
}
}
}
}
用户登录.aspx:
<form id="form1" runat="server">
用户名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br/>
密 码 :<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
<asp:Button ID="Button1" runat ="server" onclick="Button1_Click" Text="登录"/><br/>
<asp:CheckBox ID="CheckBox1" runat ="server" Text="记住用户密码"/>
<div>
</div>
</form>
用户登录.cs:
namespace 用户登录
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["ID"] != null && Request.Cookies["PWD"] != null)
{
string id = Request.Cookies["ID"].Value.ToString();
string pwd = Request.Cookies["PWD"].Value.ToString();
Response.Redirect("New.aspx? ID=" +id+"&PWD="+pwd);
}
}
教材 P117 创建用户注册页面
Register.cs
namespace User_Register
{
public partial class Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
UnobtrusiveValidationMode = new UnobtrusiveValidationMode();
if (this.txtPwd.Text != " ")
{
this.txtPwd.Attributes["value"] = this.txtPwd.Text;
}
if (this.txtPwd2.Text != " ")
{
this.txtPwd2.Attributes["value"] = this.txtPwd2.Text;
}
}
}
}
}
DB.cs:
namespace User_Register.App_Code
{
public class DB
{
public static SqlConnection DBconnection()
{
return new SqlConnection("Data Source=(LocalDB)\\
MSSQLLocalDB;AttachDbFilename=\"E:\\ 桌 面 \\User Register\\App_Data\\DB.mdf\";Integrated
Security=True;");
}
Tb_user:
CREATE TABLE [dbo].[tb_user] (
[UserName] NVARCHAR (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[PassWord] NVARCHAR (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[PassWord2] NVARCHAR (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[TrueName] NVARCHAR (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Adress] NVARCHAR (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Tel] NVARCHAR (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Postcode] NVARCHAR (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[sex] NVARCHAR (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
PRIMARY KEY CLUSTERED ([UserName] ASC)
);