急求.NET 后台登陆源码(c#语言),包括.aspx和.cs文件
发布网友
发布时间:2022-12-17 08:44
我来回答
共3个回答
热心网友
时间:2023-09-15 03:48
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test11.aspx.cs" Inherits="test11" %>
<!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>
<style type="text/css">
.style1
{
width: 73px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<table width="220px" style="align:center">
<tr>
<td class="style1">
<span lang="zh-cn">用户名:</span></td>
<td>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<span lang="zh-cn">密码:</span></td>
<td>
<asp:TextBox ID="txtpwd" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="login" runat="server" Text="登陆" onclick="login_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class test11 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void login_Click(object sender, EventArgs e)
{
string str = "server=(local);database=数据库名;user id=用户名;Password=密码;Max Pool Size=5000;";
SqlConnection myConn=new SqlConnection(str);
string myLoingID = this.txtname.Text.Trim().ToString();
string myPass = this.txtpwd.Text.Trim().ToString();
if (myLoingID == "")
{
Response.Write("<script>alert('请输入账号!');history.back();</script>");
this.txtname.Focus();
}
else if (myPass == "")
{
Response.Write("<script>alert('请输入密码!');history.back();</script>");
this.txtpwd.Focus();
}
else if (myLoingID != "" && myPass != "")
{
string Sqlstr = "select * from management where manageid =@loginname and managepwd=@loginpwd";
SqlDataAdapter sqldap = new SqlDataAdapter(Sqlstr, myConn);
sqldap.SelectCommand.Parameters.Add(new SqlParameter("@loginname", SqlDbType.Char, 10));
sqldap.SelectCommand.Parameters["@loginname"].Value = myLoingID;
sqldap.SelectCommand.Parameters.Add(new SqlParameter("@loginpwd", SqlDbType.VarChar, 80));
sqldap.SelectCommand.Parameters["@loginpwd"].Value = myPass;
DataSet ds = new DataSet();
sqldap.Fill(ds);
myConn.Close();
if (ds.Tables[0].Rows.Count > 0)
{
Response.Write("<script>window.parent.location.replace('0000_index.aspx');</script>");
}
else
{
Response.Write("<script>alert('用户名或密码错误!');history.back();</script>");
}
}
}
}
热心网友
时间:2023-09-15 03:48
动软代码生成器就可以生成这样的代码,并且动软系统框架也有现成这样的代码,你可以去看看哦
热心网友
时间:2023-09-15 03:48
上msdn网,那里有最详细的说明
以下是msdn中文网
http://msdn2.microsoft.com/zh-cn/library/default.aspx