ASPX code:
<%@ Page Language="C #"AutoEventWireup="true"CodeFile="DengLu.aspx.cs"Inherits="Denglu" %><!DOCTYPE HTML><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Headrunat= "Server"><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/> <title></title> <style>. DL{margin:0px Auto;padding:0px; Left:400px;width:304px;Height:257px; }</style></Head><Body> <formID= "Form1"runat= "Server"> <Divclass= "DL"> <H1> Login</H1> <P> </P> <P> <Asp:labelID= "Label1"runat= "Server"Text= "User name:"></Asp:label> <Asp:textboxID= "TextBox1"runat= "Server"></Asp:textbox> </P> <P> <Asp:labelID= "Label2"runat= "Server"Text= "Password:"></Asp:label> <Asp:textboxID= "TextBox2"runat= "Server"></Asp:textbox> </P> <P> </P> <P> <Asp:buttonID= "Button1"runat= "Server"Text= "Login"OnClick= "Button1_Click" /> <asp:literalID= "Literal1"runat= "Server"></asp:literal> </P> </Div> </form></Body></HTML>
CS Code:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls; Public Partial classdenglu:system.web.ui.page{PrivateUsersdatacontext context =NewUsersdatacontext (); protected voidPage_Load (Objectsender, EventArgs e) { } protected voidButton1_Click (Objectsender, EventArgs e) { //Take value stringUID =TextBox1.Text; stringPWD =TextBox2.Text; //Check the database varquery = Context.users.Where (p = p.username = = UID && P.password = =pwd); if(Query. Count () >0) { intState =query. First (). State.value; if(state = =0) {Literal1.text="<script type= ' text/javascript ' >alert (' This account is not approved! ');</script>"; } Else if(state = =1) {session["UID"] =uid; Response.Redirect ("main.aspx"); } Else{Literal1.text="<script type= ' text/javascript ' >alert (' This account failed to audit! ');</script>"; } } Else{Literal1.text="<script type= ' text/javascript ' >alert (' username or password is wrong! ');</script>"; } }}
20151223:web: Audit: Login