aspx代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DengLu.aspx.cs" Inherits="DengLu" %>
cs代码:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class DengLu : System.Web.UI.Page{ private UsersDataContext context = new UsersDataContext(); protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { //取值 string uid = TextBox1.Text; string pwd = TextBox2.Text; //查数据库 var query = context.users.Where(p => p.UserName == uid && p.PassWord == pwd); if(query.Count()>0) { int state = query.First().State.Value; if (state == 0) { Literal1.Text = ""; } else if(state == 1) { Session["uid"] = uid; Response.Redirect("Main.aspx"); } else { Literal1.Text = ""; } } else { Literal1.Text = ""; } }}