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

Reading number is top 10 articles
.net控件开发(六)之深究控件样式_[Asp.Net教程]
Asp.Net,构架
用Apache与MySQL整合实现基本身份认证_php资料_编程技术
详细解析Apache服务器实现的用户验证_php资料_编程技术
动态sql语句基本语法_[SQL Server教程]
Httpd,2.2.0虚拟主机目录权限设置问题_php资料_编程技术
解析SQL Server 2008中的新语句:MERGE_[SQL Server教程]
ASP.NET中广告控件AdRotator使用方法_[Asp.Net教程]
C#编程中的,New,关键词的几种用法_.net资料_编程技术
c#得到文件路径-多种不同格式_[Asp.Net教程]
Reading number is top 10 pictures
Sora aoi calligraphy show
Ashlynn Brooke photograph of a group4
Female model behind the bitterness, often being overcharged4
Catch prostitution woman in China
The money of more than 100 countries and regions6
The most popular girls welcome eggplant
可爱的狗熊们
泳装名模阿尔贝特妮写真
初五接财神啦!五路财神齐来到
Household design of gorgeous series
Download software ranking
网络管理员第三版
美女游泳记
WebService在.NET中的实战应用教学视频 → 第2集
SP4 for SQL2000
Unix video tutorial1
Boxer's Top ten classic battle4
尖东毒玫瑰A
Dance with duck(male prostitution)
Boxer vs Yellow4
Take off clothes to survival
delv published in(发表于) 2014/1/23 2:55:54 Edit(编辑)
ASP.NET,表单验证

ASP.NET,表单验证

ASP.NET 表单验证:代码及讲解_[Asp.Net教程]

Step 1:新建数据库(库:MyForms ;表:users ;字段:ID,userName, userPwd);
Step 2:新建网站,web.config 的文件全部代码如下:


web.config 的全部代码































Step 3:添加一个 login.aspx 页面;拖2个 TextBox ,1个Button 和1个CheckBox ;
并将CheckBox 的text 属性设为:“是否保存Cookis ";
Step 4:login.aspx 的隐藏代码如下:

login 全部隐藏代码
using System;
using System.Data;
using System.Configuration;
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.SqlClient; //导入命名空间

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 userName = TextBox1.Text.Trim();
string userPwd = TextBox2.Text.Trim();
SqlConnection con = new SqlConnection("Server=.;Database=MyForms;User ID=sa;Password=123456");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from users where userName='" + userName + "' and userPwd='" + userPwd + "'", con);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
System.Web.Security.FormsAuthentication.SetAuthCookie(this.TextBox1.Text, this.CheckBox1.Checked);
Response.Redirect("Default.aspx");
//上面两行,也可以换成下面一行,如通过验证则直接转向请求的页面,而不需要Responsel.Redirect("");
//System.Web.Security.FormsAuthentication.RedirectFromLoginPage(this.TextBox1.Text, false);
}

else
{
Response.Write("用户不合法");
}
}
}

Step 5:拖一个Button 到 Default.aspx 上,将其text 属性设为"登出",其事件代码如下:

Button 事件代码
protected void Button1_Click(object sender, EventArgs e)
{
System.Web.Security.FormsAuthentication.SignOut();
}







添加到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.