Asp登陆

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="QYLogin.aspx.cs" Inherits="YTO.WeiXinService.QYLogin" %>



<!DOCTYPE html>



<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>管理登录界面</title>

    <link href="CSS/login.css" rel="stylesheet" />

    <link href="Images/2.ico" rel="icon" />

    <script type="text/javascript" src="JS/jquery-1.11.0.js"></script>

    <script>        

        $(document).ready(function () {

            $("#logo").css("margin-top", ($(window).height() - 460) / 2 + "px");

            $("input[name='username']").focus();

            // checkform();

            $("#forget-password").click(function (e) {

                $("#loginform").hide();

                $("#forgetPwd").show(200);

                e.preventDefault();

            });

            $("#btnforgetsubmit").click(function (e) {

                $("#loginform").slideDown(200);

                $("#forgetPwd").slideUp(200);

                e.preventDefault();

            });

        });

    </script>

</head>

<body>

    <div id="logo">

        <img alt="HongCMS" src="Images/logo-login.png">

    </div>

    <div id="login">

        <form name="form1" method="post" runat="server" action="QYLogin.aspx?frm=Login">

            <div id="loginform">

                <asp:Label ID="errorWarning" Text="" runat="server" />

                <p id="info">请输入用户名和密码</p>

                <div class="control-group">

                    <span class="icon-user"></span>

                    <asp:TextBox ID="username" runat="server" Text=""></asp:TextBox>

                    <asp:RequiredFieldValidator ErrorMessage="" ControlToValidate="username" runat="server" />

                </div>

                <div class="control-group">

                    <span class="icon-lock"></span>

                    <asp:TextBox ID="pwd" runat="server" Text="" TextMode="Password" />

                    <asp:RequiredFieldValidator ErrorMessage="" ControlToValidate="pwd" runat="server" />

                </div>

                <div class="remember-me">

                    <input id="rm" value="1" type="checkbox" name="remember">

                    <label for="rm">记住我</label>

                    <a id="forget-password" href="#">忘记密码?</a>

                </div>

                <div class="login-btn">

                    <asp:Button ID="btnlogin" Text="登 录" runat="server" OnClientClick="return checkform()" OnClick="btnlogin_Click" />

                </div>

            </div>

            <%--  

        <form id=forgotform class=hide name="form2" method=post runat="server" action="QYLogin.aspx?frm=ForgetPwd">--%>

            <div id="forgetPwd" style="display:none;">

                <p id="info2">请输入Email地址重设密码.</p>

                <div class="control-group">

                    <span class="icon-mail"></span>                  

                    <asp:TextBox runat="server" Text="" />

                </div>

                <div class="login-btn forget-btn">                  

                    <asp:Button ID="btnforgetsubmit" Text="提 交" runat="server" OnClick="btnforgetsubmit_Click" />

                </div>

            </div>

        </form>

    </div>

    <div id="login-copyright"><a href="http://www.yto.net.cn" target="_blank">www.yto.net.cn</a> </div>









</body>

</html>

2.后台代码

using System;

using System.Collections.Generic;

using System.Web.UI;

using YTO.WeiXin.Core;

using YTO.WeiXin.Model;



namespace YTO.WeiXinService

{

    public partial class QYLogin : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {



        }

        protected void btnlogin_Click(object sender, EventArgs e)

        {

            if (Page.IsValid)

            {

                string userName1 = username.Text.ToString().Trim();

                string pwd1 = pwd.Text.ToString().Trim();

                AccountInfo[] account = AccessTo.account;               

                IList<AccountInfo> acclist = new List<AccountInfo>();

                foreach (var item in account)

                {

                    if (item.Username == userName1 && item.Pwd == pwd1)

                    {

                        acclist.Add(item);

                    }

                }

                if (acclist.Count > 0)

                {

                    //Session[""]="";

                    CustomizeSession CustSession = new CustomizeSession();

                    CustSession.SetSession("yto_qiyun_session_username", acclist[0].Username);                 

                    CustSession.SetSession("yto_qiyun_session_pwd", acclist[0].Pwd);                 

                    string remember = Request.Form["remember"];

                    if (remember == "1")

                    {

                        Response.Cookies["yto_qiyun_username"].Value = acclist[0].Username;

                        Response.Cookies["yto_qiyun_username"].Expires = DateTime.Now.AddDays(3);

                        Response.Cookies["yto_qiyun_pwd"].Value = acclist[0].Pwd;

                        Response.Cookies["yto_qiyun_pwd"].Expires = DateTime.Now.AddDays(3);

                    }

                    Response.Redirect("Management/AuthManagement.aspx");

                }

                else

                {

                    errorWarning.Text = "*用户名或密码错误,请重新输入!";

                    errorWarning.Style["display"] = "inline";

                    username.Text = "";

                    pwd.Text = "";

                    //Response.Redirect("QYLogin.aspx");

                    //Response.Write("<Script language='JavaScript'>alert('用户名或者密码错误!');</Script>");

                }

            }

            else

            {

                errorWarning.Text = "*用户名或密码不可以为空!";

                errorWarning.Style["display"] = "inline";

                username.Text = "";

                pwd.Text = "";

            }

        }

        protected void btnforgetsubmit_Click(object sender, EventArgs e)

        {



        }

    }

}

 

你可能感兴趣的:(asp)