[原创]使用ASP.net的Form安全模刑开发的一个工程.
来源:互联网 发布:淘宝水果不能拒收吗 编辑:程序博客网 时间:2024/06/05 18:22
web.config中加入:
<authentication mode="Forms">
<forms name="WebForms" loginUrl="login.aspx"/>
</authentication>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
login.aspx.cs文件中的代码:
先要引用:
using System.Web.Security;
using System.Security.Cryptography;
这两个命名空间
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 WebTools;
using System.Web.Security;
using System.Security.Cryptography;
using System.Data.SqlClient;
namespace WebForm
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : 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.Label Label1;
public Tools Wtools=new Tools();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web Form Designer generated code
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.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
string sql="select * from user_info where username="+TextBox1.Text+" and password="+TextBox2.Text;
SqlDataReader read;
read=Wtools.SqlReader(sql,Wtools.connStr);
if(read.Read())
{
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text,false);
}
else
{
Label1.Text="用户名和密码不对";
}
read.Close();
}
}
}
<authentication mode="Forms">
<forms name="WebForms" loginUrl="login.aspx"/>
</authentication>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
login.aspx.cs文件中的代码:
先要引用:
using System.Web.Security;
using System.Security.Cryptography;
这两个命名空间
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 WebTools;
using System.Web.Security;
using System.Security.Cryptography;
using System.Data.SqlClient;
namespace WebForm
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : 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.Label Label1;
public Tools Wtools=new Tools();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web Form Designer generated code
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.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
string sql="select * from user_info where username="+TextBox1.Text+" and password="+TextBox2.Text;
SqlDataReader read;
read=Wtools.SqlReader(sql,Wtools.connStr);
if(read.Read())
{
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text,false);
}
else
{
Label1.Text="用户名和密码不对";
}
read.Close();
}
}
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=394684
相关文章:
- 动态添加web控件 2006-04-26 lengyuewuhen
- MD5数据加密 2005-06-24 NUNUblog
- C#通过输入项创建DataTable 2004-07-02 delphine
- QuicklyBuildModel/Login.aspx.cs[快速类建模型登录页面代码] 2004-06-29 wildhope
- ASP.NET生成静态网页的代码(已调试通过) 2005-11-18 ITFLY8
- [原创]使用ASP.net的Form安全模刑开发的一个工程.
- [原创]使用ASP.net的Form安全模刑开发的一个工程.
- ASP.NET 安全认证(Form 认证奇怪的失败)
- ASP.NET 安全认证(登录的使用)
- [原创].NET中Form.AutoScrollPosition的运用
- 写asp.net论坛时用的一个技巧[原创]
- ASP.NET的Form表单
- Asp.net的身份验证 Form
- asp.net的Form验证
- Asp.net Web Form开发的页面生命周期模型
- ASP.net使用Form验证时Ajaxpro的配置
- Asp.Net实现FORM认证的一些使用技巧
- asp.net 中使用easyui的form控件
- asp.net 使用urlrewrite之后的form action postback
- ASP.NET 实现FORM认证的一些使用技巧
- [原创]ASP.NET环境下完整的treeview使用类
- asp.net使用SerialPort的方法(VB简单版)[原创]
- ASP.net 的安全机制
- 在ASP.NET中实现多文件上传
- PB应用程序编译发布技术研究
- One of My Blogs was closed of indefinite duratio on 3 September, 2006.
- javascript学习笔记
- 代码编写规范说明书
- [原创]使用ASP.net的Form安全模刑开发的一个工程.
- 程序人生(旅游篇-苏州之行)
- .Net的编码规范
- JavaScript中this关键字使用方法详解
- 程序人生(二十二 )
- 网络socket编程指南
- A Visting Card and A Logo (By Daiyan)
- 开发小记
- HTML文件中也玩include文件包含