Controllers/AdminController.cs

(开头部分) 3KB

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Hosting;
using System.Xml;
using FSBlog.Models;
using System.IO;

namespace FSBlog.Controllers
{
    public class AdminController : Controller
    {
        /// <summary>
        /// 注入目录
        /// </summary>
        private readonly IHostingEnvironment _hostingEnvironment;

        public AdminController(IHostingEnvironment hostingEnvironment)
        {
            _hostingEnvironment = hostingEnvironment;
        }
        
        [HttpGet]
        public async Task<IActionResult> Index()
        {
            return View();
        }

        [HttpPost]
        public async Task<IActionResult> Index([FromHeader]string uname, [FromHeader]string upwd)
        {
            if (string.IsNullOrEmpty(uname) && string.IsNullOrEmpty(upwd))
            {
                return Json(new { error = "error" });
            }
            if (uname == "admin" && upwd == "51aspx")
            {
                HttpContext.Session.SetString("login", "success");
                return Json(new { error = "success" });
            }
            else
            {
                return Json(new { error = "error" });
            }
        }

        public async Task<IActionResult> Manage()
        {
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("login")))
            {
                return Redirect("/Admin/Index");
            }
            else
            {
                ViewData["blist"] = Blog.GetAllBlogs(_hostingEnvironment.WebRootPath + Blog.BLOGRECARDPATH);
                return View();
            }
后面还有 38 行代码,解锁后查看完整代码

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

AI 解读

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

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