Ajax+asp.net to achieve User login _ practical skills

Source: Internet
Author: User

Take user Login As an example to practice the use of Ajax

Login.html

<! 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 ("Login succeeded");
        Response.End ();
      }
      else
      {
        Response.Write ("Login Failed");
        Response.End ();}}}


Server.aspx

<%@ Page language= "C #" autoeventwireup= "true" codebehind= "Server.aspx.cs" inherits= "Ajaxtest.server"%>
 
<! DOCTYPE html>
 
 
 

The above mentioned is the entire content of this article, I hope you can enjoy.

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.