首页:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width:600; text-align: left;">
<tr>
<td colspan="3" style="height: 77px">
<asp:Label ID="Label1" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<span style="font-size: 24pt; color: #ff0000">已是会员,请在这里登录</span></td>
</tr>
<tr>
<td style="width: 116px; height: 39px;">
<span style="font-size: 16pt">
用户名:</span></td>
<td colspan="2" style="height: 39px">
<asp:TextBox ID="TextBox1" runat="server" Width="215px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 116px; height: 47px;">
<span style="font-size: 16pt">
密码:</span></td>
<td colspan="2" style="height: 47px">
<asp:TextBox ID="TextBox2" runat="server" Width="214px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 116px">
</td>
<td style="width: 138px">
<asp:Button ID="Button1" runat="server" Font-Size="14pt" Text="登 录" Width="89px" OnClick="Button1_Click" /></td>
<td style="width: 134px">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
登陆后台功能:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Server.MapPath("/WebSite21/App_Data/news.mdb");
OleDbConnection oleConnection = new OleDbConnection(ConnStr);
oleConnection.Open();
OleDbCommand mycommand = new OleDbCommand("select * from login where username='" + TextBox1.Text + "' and userpwd='" + TextBox2.Text + "'", oleConnection);
int count = Convert.ToInt32(mycommand.ExecuteScalar());
if (count > 0)
{
Session["name"] = TextBox1.Text;
Response.Redirect("cg.aspx");
}
else
{
Label1.Text = "<script language=javascript>alert( '用户名或密码错误')</script>";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox1.Focus();
}
oleConnection.Close();
}
}
登陆成功后转向cg.aspx页面
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class cg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Session["name"]);
}
}