⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logincontrol.ascx.cs

📁 guan yu pai ke xi tong de ruan jian
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
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 Y2T03.CourseScheduler.CourseBLL;
using Y2T03.CourseScheduler.CourseModel;

public partial class LoginControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.txtLoginName.Focus();
    }

    protected void btnUserlogin_click(object sender, EventArgs e)
    {
        try
        {
            string name = this.txtLoginName.Text.Trim();
            string password = this.txtPassword.Text.Trim();

            if (AccountSafetyBLL.Login(name, password))
            {
                //Account account = new Account();

                //account.LoginName = name;
                //account.Password = password;

                //this.Session["CurrentUser"] = account;   // 创建会话

                //HttpCookie myCookie = new HttpCookie("LoginName");
                //myCookie.Value = account.LoginName;
                //Response.Cookies.Add(myCookie);

                System.Web.Security.FormsAuthentication.SetAuthCookie("LoginName", false);  // false 表示不创建永久的Cookie
                System.Web.Security.FormsAuthentication.RedirectFromLoginPage("LoginName", false);  // false 表示不创建永久的Cookie

                this.Page.Response.Redirect("~/UserManage.aspx");
            }
            else
            {
                PopupMessage("用户名或者密码错误!");

                this.txtLoginName.Text = string.Empty;
            }
        }
        catch (Exception ex)
        {
            string err = ex.Message;
        }
    }

    /// <summary>
    /// 弹出操作结果
    /// </summary>
    /// <param name="message">弹出对话框信息内容</param>
    protected void PopupMessage(string message)
    {
        try
        {
            ClientScriptManager csm = this.Page.ClientScript;   // 获取管理客户端脚本的方法
            Type type = this.GetType();     // 获取类型
            string csKey = "PopupMessage";  // 设置消息

            //
            // 判断是否已经注册了启动脚本
            //
            if (!csm.IsStartupScriptRegistered(type, csKey))
            {
                string script = string.Format("alert('{0}');", message);    //格式化输出弹出消息的内容
                csm.RegisterStartupScript(type, csKey, script, true);   //注册启动脚本
            }
        }
        catch (Exception ex)
        {
            string err = ex.Message;
        }
    }
}

⌨️ 快捷键说明

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