The first step:
1) First Use "Codesmith" to instantiate the Examinee class and generate a method for the entity class to connect to the database, which exists under the "App_Code" folder under the solution.
Modify the connection to a database;
Private SqlConnection _conn; Public DBConnection () { = system.web.configuration.webconfigurationmanager.connectionstrings["conn" ]. ToString (); New SqlConnection (connectionString); }
To modify configuration information in config:
1<configuration>2 3<system.web>4<compilation debug="true"targetframework="4.5"/>5"4.5"/>6</system.web>7<connectionStrings>8<add name ="Conn"connectionstring="server=.; Database=kaoshixitong;user=sa;pwd=123"/>9</connectionStrings>Ten</configuration>
The second step: first design the Good interface:
2) write the code and implement the function.
Login Code
1 //Login Button2 protected voidButton1_Click (Objectsender, EventArgs e)3 {4 stringuser =Txt_user. Text.trim ();5 if(User = ="")6 {7Response.Write ("<font size=16> cannot be empty </font>");//output in website production is response8 }9 stringMima =Txt_mima. Text.trim ();TenExamineedata da =NewExamineeda (). Select (User,mima);//invoking a database method One if(da!=NULL) A { -Response.Redirect ("http://baidu.com"); - } the Else - { -Label1.visible =true; - } + if(TextBox1.Text.Trim () = =linkbutton1.text) - { +Response.Write ("http://baidu.com");//verify code entered correctly, jump directly to Baidu A } at Else - { -Response.Write ("validation Error");//when an error is entered - } - } - //Random 4-bit digital verification code in protected voidLinkButton1_Click (Objectsender, EventArgs e) - { toRandom Suiji =NewRandom ();//Random number + for(inti =0; I <4; i++) - { the if(i = =0) * { $Linkbutton1.text = Suiji. Next (0,Ten). ToString ();Panax Notoginseng } - Else the { +Linkbutton1.text + = Suiji. Next (0,Ten). ToString (); A } the } +}
3):
01-19asp.net Foundation--Website Login and verification