Asp.NETPersonnalBlogSystem/Account/Login.aspx.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Web;
using Asp.NETPersonnalBlogSystem.BLL;
using Asp.NETPersonnalBlogSystem.Models;

namespace Asp.NETPersonnalBlogSystem.Account
{
    /// <summary>
    /// 登录页面后端代码
    /// 处理用户登录验证和会话管理
    /// </summary>
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["CurrentUser"] != null)
                {
                    var user = Session["CurrentUser"] as User;
                    if (user != null && user.Role == 1)
                    {
                        Response.Redirect("~/Admin/Default.aspx");
                    }
                    else
                    {
                        Response.Redirect("~/Default.aspx");
                    }
                }
            }
        }

        /// <summary>
        /// 登录按钮点击事件
        /// </summary>
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string userName = txtUserName.Text.Trim();
            string password = txtPassword.Text;

            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                ShowMessage("用户名和密码不能为空!");
                return;
            }

            try
            {
                UserService userService = new UserService();
                var user = userService.Login(userName, password);

                if (user != null)
                {
                    Session["CurrentUser"] = user;
                    Session["UserId"] = user.UserId;
                    Session["UserName"] = user.UserName;
                    Session["UserRole"] = user.Role;

                    LogService logService = new LogService();
                    logService.LogInfo("User", "用户登录", $"用户 {userName} 登录成功", user.UserId, userName, Request.UserHostAddress);
后面还有 41 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。