码迷,mamicode.com
首页 > Web开发 > 详细

Web登陆实例-—同步用户名

时间:2014-10-31 23:46:37      阅读:482      评论:0      收藏:0      [点我收藏+]

标签:vb.net   html   

    之前登陆学校的教务系统或者考试系统,进入界面都会有“欢迎***登陆本系统”,当时就觉得挺高级。现在轮

到自己做这个例子,突然感觉是so easy!

    只需简单几步,就可可以搞定。

(1)验证登陆

    编写服务器代码如下:

 protected void Page_Load(object sender, EventArgs e)
        {
            string userName = Request.Form["userName"].ToString();                     //获取用户名
            string userPwd = Request.Form.Get("userPwd").ToString();                    //获取密码
            SqlConnection con = new SqlConnection("server=.;database=login;uid=sa;pwd=***");   //连接数据库
            con.Open();
            SqlCommand cmd = new SqlCommand("select count(*) from login where userName='"+userName+"'  and  userPwd='"+userPwd+"'" ,con);
            int count = Convert.ToInt32(cmd.ExecuteScalar());
            if (count>0)
            {
                Response.Redirect("main.aspx");     //验证成功
            }
            else
            {
                Response.Redirect("loginFail.html");   //验证失败
            }
        }  

(2)同步用户名

Response.Redirect("main.aspx?userName="+userName);          //隐含的是get提交 .传入用户名

//获取用户名:显示欢迎登陆
string userName = Request.QueryString["userName"].ToString();          //get提交获取数据的方法
Response.Write("<font size=24  color=red> 欢迎 " + userName + "光临本网站</font>");     //登陆后同步用户名 

(3)效果

bubuko.com,布布扣




点睛

    学习最重要的是兴趣,有时候突然很简单的实现了自己以前认为很难的事情,学习的兴趣,效率就会成几十倍,

几百倍的增加。小小的例子,不仅巩固了我们所学的知识,而且对提高我们的学校兴趣和效率很有帮助。


Web登陆实例-—同步用户名

标签:vb.net   html   

原文地址:http://blog.csdn.net/zhangzijiejiayou/article/details/40661793

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!