01-19asp.net Foundation--Website Login and verification

Source: Internet
Author: User
Tags connectionstrings

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

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.