Ajax + asp.net implement user login, ajaxasp.net
Using user logon as an example to practice ajax usage
Login.html
Success <! DOCTYPE html>
DAL. cs
using System;using System.Collections.Generic;using System.Data;using System.Data.SqlClient;using System.Linq;using System.Web; namespace AJAXtest{ public class DAL { private string connstr = "server=acer-pc;database=mydatabase;user id=sa;password=123456"; public DataTable selectDB(string sql) { DataTable dt = new DataTable(); try { SqlConnection conn = new SqlConnection(connstr); SqlDataAdapter sda = new SqlDataAdapter(sql, conn); sda.Fill(dt); } catch(Exception e) {} return dt; } }}
BLL. cs
using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Web; namespace AJAXtest{ public class BLL { public bool login(string username,string password) { try { string sql = "select password from Users where username='" + username + "'"; DAL sqlSelect = new DAL(); DataTable dt = sqlSelect.selectDB(sql); if (dt.Rows[0]["password"].ToString() != password) return false; } catch (Exception) { } return true; } }}
Server. aspx. cs
Using System; using System. collections. generic; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; namespace AJAXtest {public partial class Server: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {string username = Request ["username"]. toString (); string password = Request ["password"]. toString (); BLL B = new BLL (); if (B. login (username, password) {Response. write ("Logon successful"); Response. end ();} else {Response. write ("Logon Failed"); Response. end ();}}}}
Server. aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Server.aspx.cs" Inherits="AJAXtest.Server" %> <!DOCTYPE html>
The above is all the content of this article. I hope you will like it.