[原创]使用ASP.net的Form安全模刑开发的一个工程.
2006-09-05 17:14
567 查看
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();
}
}
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=394684
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
<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 lengyuewuhenMD5数据加密 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 开发的一个东平人才网招聘程序
- 使用ASP.NET Core MVC 和 Entity Framework Core 开发一个CRUD(增删改查)的应用程序
- 使用ASP.NET Core MVC 和 Entity Framework Core 开发一个CRUD(增删改查)的应用程序
- 项目开发中的一些注意事项以及技巧总结 基于Repository模式设计项目架构—你可以参考的项目架构设计 Asp.Net Core中使用RSA加密 EF Core中的多对多映射如何实现? asp.net core下的如何给网站做安全设置 获取服务端https证书 Js异常捕获
- 使用EF+ASP.NET MVC+Bootstrap开发一个功能强大的问卷调查系统
- ASP.NET企业开发框架IsLine FrameWork系列之十二--使用Session、Cookie与安全支持
- 使用一般处理程序,模拟ASP.NET MVC,开发一个轻量级的学习版MVC框架。
- ASP.NET企业开发框架IsLine FrameWork系列之十二--使用Session、Cookie与安全支持
- 关于使用Asp.net导出Excel,遭遇“LinkButton必须放在一个具有runat=server的标签的Form”的解决方案。
- 使用IsLine FrameWork开发ASP.NET程序之八—使用Session、Cookie与安全支持
- 如何在asp.net中使用多线程及队列,异步处理一个耗时的任务(原创)
- asp.net开发中经常使用到的一个验证码(实用)
- Ninject 在 Winform、 Asp.net MVC中结合EntityFramework的使用( 注入同一个DbContext的使用方法) - 原创
- ASP.NET没有魔法——ASP.NET MVC使用Area开发一个管理模块
- [翻译]ASP.NET MVC 3 开发的20个秘诀(十四)[20 Recipes for Programming MVC 3]:使用Ajax提交Form
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- [转]Asp.Net MVC使用HtmlHelper渲染,并传递FormCollection参数的陷阱 【转】
- 使用ASP.NET开发WAP强制输出WML
- 如何使用谷歌的自定义搜索引擎来搜寻一个ASP.NET网站