[原创]使用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();
        }
    }
}



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
 
原创粉丝点击