adminlogin.aspx.cs

来自「一个网上书店的源码」· CS 代码 · 共 58 行

CS
58
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MyBookShop.BLL;
using MyBookShop.Models;

public partial class Admin_AdminLogin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void imgbtnSure_Click(object sender, ImageClickEventArgs e)
    {
        User user;
        if (UserManager.AdminLogin(this.txtLoginId.Text, this.txtLoginPwd.Text, out user))
        {
            Session["AdminUser"] = user;
            #region 旧代码
            //FormsAuthenticationTicket tkt;
            //string cookiestr;
            //HttpCookie ck;
            //tkt = new FormsAuthenticationTicket(1, user.Name, DateTime.Now, DateTime.Now.AddMinutes(30), true, "your custom data"); //创建一个验证票据
            //cookiestr=FormsAuthentication.Encrypt(tkt);//并且加密票据
            //ck=new HttpCookie(FormsAuthentication.FormsCookieName,cookiestr);// 创建cookie
            //ck.Path=FormsAuthentication.FormsCookiePath;//cookie存放路径
            //Response.Cookies.Add(ck);
            #endregion
            string strRedirect;
            strRedirect = Request["ReturnUrl"];

            System.Web.Security.FormsAuthentication.SetAuthCookie(user.Name, true);
            if(strRedirect==null)
                Response.Redirect("~/Admin/ListAllUsers.aspx");
            Response.Redirect(strRedirect);
        }
        else
        {
            Response.Redirect("~/Error.aspx");
        }
        
    }

    protected void imgbtnCancel_Click(object sender, ImageClickEventArgs e)
    {
        this.txtLoginId.Text = String.Empty;
        this.txtLoginPwd.Text = String.Empty;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?