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