Web Login Instance--Synchronizing user name

Source: Internet
Author: User

Before landing the school's educational system or examination system, access to the interface will have "Welcome to the system", at that time felt quite advanced. Now turn

to self Have done This example, suddenly felt so easy!

Just a few simple steps, you can get it done.

(1) Verify login

Write the server code as follows:

protected void Page_Load (object sender, EventArgs e)        {            string userName = request.form["UserName"]. ToString ();                     Gets the user name            string userpwd = Request.Form.Get ("Userpwd"). ToString ();                    Get            the password SqlConnection con = new SqlConnection ("server=.; database=login;uid=sa;pwd=*** ");   Connect Database            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");     Validation succeeded            }            else            {                Response.Redirect ("loginfail.html");   Validation failed            }        }  

(2) synchronizing user names

Response.Redirect ("main.aspx?username=" +username);          The implicit is a get commit. Incoming user name

Get user name: Display Welcome Login String userName = request.querystring["UserName"]. ToString ();          Get Submit method of obtaining Data Response.Write ("<font size=24  color=red> Welcome" + UserName + "visit this website </font>");     

(3) Effect




Finishing Toucheslearning the most important is the interest, sometimes suddenly very simple to achieve their own previously thought difficult things, learning interest, efficiency will become a few10 times times,hundreds of times times the increase. A small example not only reinforces what we have learned, but also helps to improve our school's interest and efficiency.


Web Login Instance--Synchronizing user name

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.