哪位兄弟能给我一个登陆的小例子 越简单越好啊,谢谢,分不够可再加 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考:http://support.microsoft.com/kb/301240/zh-cn private bool checkUser( string user,string pwd )//检查 用户名是否存在 { bool bTemp = false; DBConn myDB = new DBConn(); string mySql = "select * from table where LoginName='" + user + "'and PassWord='"+pwd+"'"; SqlDataReader mydr = myDB.getDataReader( mySql ); if( mydr.Read() ) { bTemp = true; } else { bTemp = false; } mydr.Close(); myDB.Close(); return bTemp; }private void login_Click(object sender, System.EventArgs e) { string strLoginName=LoginName.Text.ToString().Trim(); string strPassWord=PassWord.Text.ToString().Trim(); strLoginName=CleanString.htmlInputText(strLoginName); strPassWord=CleanString.htmlInputText(strPassWord); strPassWord = FormsAuthentication.HashPasswordForStoringInConfigFile( strPassWord ,"MD5"); if( checkUser(strLoginName,strPassWord)) { Response.Redirect("main.aspx"); } else{ Response.Write("<script>"); Response.Write("alert('错误!请确认用户名或密码!')"); Response.Write("</script>"); } } 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;using System.Data.OleDb;namespace Weblogin{ /// <summary> /// weblogin 的摘要说明。 /// </summary> public class weblogin : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox TextBox1; protected System.Web.UI.WebControls.TextBox TextBox2; protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1; protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1; protected System.Web.UI.WebControls.Button Button2; private void Page_Load(object sender, System.EventArgs e) {// if(!this.IsPostBack)// {// // } // 在此处放置用户代码以初始化页面 } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Button2.Click += new System.EventHandler(this.Button2_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Button2_Click(object sender, System.EventArgs e) { TextBox1.Text = ""; TextBox2.Text = ""; Session.Clear(); } private void Button1_Click(object sender, System.EventArgs e) { try { OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= "+Server.MapPath("admin.mdb")); con.Open(); OleDbCommand com = new OleDbCommand("select * from admin where user='"+TextBox1.Text+"'and paw='"+TextBox2.Text+"'",con); if(com.ExecuteScalar()!=null) { Session["kk"]=this.TextBox1.Text.ToString(); con.Close(); Response.Redirect("admin.aspx"); } else {// Response.Write("<script language='javascript'>alert('用户名或密码错误!')</script>"); Response.Redirect("weblogin.aspx"); } } catch (Exception ee) { Response.Write(ee.Message.ToString());// Response.Redirect("weblogin.aspx"); }// finally// {// // } } }} <%@ Page language="c#" Codebehind="weblogin.aspx.cs" AutoEventWireup="false" Inherits="Weblogin.weblogin" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML> <HEAD> <title>weblogin</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <FONT face="宋体"> <TABLE id="Table1" style="Z-INDEX: 101; LEFT: 208px; POSITION: absolute; TOP: 184px" cellSpacing="0" cellPadding="0" width="300" align="center" border="0"> <TR> <TD style="WIDTH: 121px" align="right">用户名:</TD> <TD style="WIDTH: 189px"> <asp:TextBox id="TextBox1" runat="server"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="请输入用户名" ControlToValidate="TextBox1">*</asp:RequiredFieldValidator></TD> </TR> <TR> <TD style="WIDTH: 121px" align="right">密 码:</TD> <TD style="WIDTH: 189px"> <asp:TextBox id="TextBox2" runat="server"></asp:TextBox></TD> </TR> <TR> <TD style="WIDTH: 121px; HEIGHT: 34px" align="right"> <asp:Button id="Button1" runat="server" Text="登录"></asp:Button></TD> <TD style="WIDTH: 189px; HEIGHT: 34px" align="center"> <asp:Button id="Button2" runat="server" Text="取消"></asp:Button></TD> </TR> </TABLE> <asp:ValidationSummary id="ValidationSummary1" style="Z-INDEX: 102; LEFT: 304px; POSITION: absolute; TOP: 296px" runat="server"></asp:ValidationSummary></FONT> </form> </body></HTML> asp.net上传图片问题 在vs.net2003下服务器控件怎样获取焦点? 请问怎样在当前窗口关闭另一个窗口? 大家看看在 Response.Write 里如何使用变量! 关于smartGirdview的问题 请教各位? 怎么动态的绑定datalist中的控件? 急:一个困扰我一星期的问题,解决后马上散分(见里面) 我再问!!100分!!! 为什么用asp.net作的程序比asp做的同样功能的程序慢? 请asp.net专家解释 正则表达式里面 [] 和 () 有什么区别?呵呵,请教.... 在页面上加入了一个treeview,我点击一下,整个页面都在动
http://support.microsoft.com/kb/301240/zh-cn
{
bool bTemp = false;
DBConn myDB = new DBConn();
string mySql = "select * from table where LoginName='" + user + "'and PassWord='"+pwd+"'";
SqlDataReader mydr = myDB.getDataReader( mySql );
if( mydr.Read() )
{
bTemp = true;
}
else
{
bTemp = false;
} mydr.Close();
myDB.Close();
return bTemp;
}private void login_Click(object sender, System.EventArgs e)
{
string strLoginName=LoginName.Text.ToString().Trim();
string strPassWord=PassWord.Text.ToString().Trim(); strLoginName=CleanString.htmlInputText(strLoginName);
strPassWord=CleanString.htmlInputText(strPassWord); strPassWord = FormsAuthentication.HashPasswordForStoringInConfigFile( strPassWord ,"MD5"); if( checkUser(strLoginName,strPassWord))
{
Response.Redirect("main.aspx"); }
else{
Response.Write("<script>");
Response.Write("alert('错误!请确认用户名或密码!')");
Response.Write("</script>");
}
}
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;
using System.Data.OleDb;
namespace Weblogin
{
/// <summary>
/// weblogin 的摘要说明。
/// </summary>
public class weblogin : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
protected System.Web.UI.WebControls.Button Button2;
private void Page_Load(object sender, System.EventArgs e)
{
// if(!this.IsPostBack)
// {
//
// }
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button2_Click(object sender, System.EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
Session.Clear();
} private void Button1_Click(object sender, System.EventArgs e)
{
try
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= "+Server.MapPath("admin.mdb"));
con.Open();
OleDbCommand com = new OleDbCommand("select * from admin where user='"+TextBox1.Text+"'and paw='"+TextBox2.Text+"'",con);
if(com.ExecuteScalar()!=null)
{
Session["kk"]=this.TextBox1.Text.ToString();
con.Close();
Response.Redirect("admin.aspx");
}
else
{
// Response.Write("<script language='javascript'>alert('用户名或密码错误!')</script>");
Response.Redirect("weblogin.aspx");
}
}
catch (Exception ee)
{
Response.Write(ee.Message.ToString());
// Response.Redirect("weblogin.aspx");
}
// finally
// {
//
// }
}
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>weblogin</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<TABLE id="Table1" style="Z-INDEX: 101; LEFT: 208px; POSITION: absolute; TOP: 184px" cellSpacing="0"
cellPadding="0" width="300" align="center" border="0">
<TR>
<TD style="WIDTH: 121px" align="right">用户名:</TD>
<TD style="WIDTH: 189px">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="请输入用户名" ControlToValidate="TextBox1">*</asp:RequiredFieldValidator></TD>
</TR>
<TR>
<TD style="WIDTH: 121px" align="right">密 码:</TD>
<TD style="WIDTH: 189px">
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox></TD>
</TR>
<TR>
<TD style="WIDTH: 121px; HEIGHT: 34px" align="right">
<asp:Button id="Button1" runat="server" Text="登录"></asp:Button></TD>
<TD style="WIDTH: 189px; HEIGHT: 34px" align="center">
<asp:Button id="Button2" runat="server" Text="取消"></asp:Button></TD>
</TR>
</TABLE>
<asp:ValidationSummary id="ValidationSummary1" style="Z-INDEX: 102; LEFT: 304px; POSITION: absolute; TOP: 296px"
runat="server"></asp:ValidationSummary></FONT>
</form>
</body>
</HTML>