All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
用ASP.NET开发电子商务网站对数据库表的设计_[Asp.Net教程]
PHP与MySQL中的SQL注入式漏洞_[PHP教程]
php.ini配置,php.ini,中的,php-5.2.0,配置指令详解_php资料_编程技术
PHP 5.0中多态性的实现方案浅析_[PHP教程]
Visual C++ 6.0教程:c++数据类型之结构
ASP.NET2.0站点登录、导航与权限管理_[Asp.Net教程]
让你的.NET程序兼容不同版本的Dll文件_[Asp.Net教程]
ASP.NET技巧:HTTP性能调优之设置连接失效时间_.net资料_编程技术
利用UrlRewrite,asp.net动态生成htm页面(补充说明)_[Asp.Net教程]
HTML组件HTML COMPONENTS之三_[Html教程]
Reading number is top 10 pictures
Cesarean section, bloody, silently into it!1
西方气质的东方美女3
美女
Beautiful Japanese beauty(漂亮的日本美女)3
The sixties of the last century, China is such a kill pig
中国女孩大胆自拍,显露完美身材
Terrorist smile the largest human history an explosion1
Play for Free show breast in a world of ice and snow
教你22句话
关于海盗的研究2
Download software ranking
VC++6.0简体中文版
Take off clothes to survival
Tram sex maniac 2 (H) rar bag19
The hero
传奇私服架设教程
jdk1.5
Boxer's Top ten classic battle10
Ashlynn Video2
Tram sex maniac 2 (H) rar bag18
虚拟机5.5.3版
归海一刀 published in(发表于) 2014/1/30 0:59:49 Edit(编辑)
asp.net实现简单的用户登录_[Asp.Net教程]

asp.net实现简单的用户登录_[Asp.Net教程]

asp.net实现简单的用户登录_[Asp.Net教程]


在.NET2.0中已经有了登录和注册控件,可以轻松的实现用户登录和注册模块的建设,并且后台能自动生成数据库,建立相应的数据表,极大的方便了用户的开发和管理~在2.0中并且有强大成员角色管理,通过web.config文件能很好的管理用户的访问权限,在这里也就不废话了,进入正题.
首先在web.config文件中添加连接数据库的连接字符串



新建一个用户控件这是后台代码:
using System;
using System.Data;
using System.Data.SqlClient;
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 WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{


}
protected void Button1_Click(object sender, EventArgs e)
{
string t1=TextBox1.Text;
string t2=TextBox2.Text;
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["kuite"].ConnectionString;
cmd.Connection = conn;
cmd.CommandText = "select id,psw from customer where id='" + t1 + "' and psw='" + t2 + "'";
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Session["user"] = t1;
Response.Redirect("Hello.aspx");
}
else
{
Label3.Text = "用户名或密码错误";
}
}
}



用户控件前台代码:


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>













































onClick="Button1_Click" />













简单的登录页面

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>
<%@ Register TagPrefix="uc1" TagName="usctr" Src="~/WebUserControl.ascx" %>




设计家园











登录成功后的页面:

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 Hello : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string s1 = (string)Session["user"];
Response.Write("欢迎光临" + s1);
}
}


就这样了~我学编程有段时间了,第一次发表文章.
学习阶段,技术不深,望广大高手指点.以后会发表更好的文章~


来源:http://www.cnblogs.com/kuite







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.