src/ZKEACMS/Filter/RenderRefererPageAttribute.cs

(开头部分) 2KB

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

/* http://www.zkea.net/ 
 * Copyright (c) ZKEASOFT. All rights reserved. 
 * http://www.zkea.net/licenses */

using Microsoft.AspNetCore.Mvc.Filters;
using ZKEACMS.Page;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Mvc;
using Easy.Extend;
using System;
using System.Net;

namespace ZKEACMS.Filter
{
    /// <summary>
    /// This is used to rebuild current page when submit form while validating model failed.
    /// </summary>
    public class RenderRefererPageAttribute : WidgetAttribute
    {
        private string GetPagePath(FilterContext filterContext)
        {
            return filterContext.HttpContext.Request.Form["CurrentPagePath"];
        }
        public override PageEntity GetPage(ActionExecutedContext filterContext)
        {
            string pagePath = GetPagePath(filterContext);
            using (var pageService = filterContext.HttpContext.RequestServices.GetService<IPageService>())
            {
                return pageService.GetByPath(pagePath, false);
            }
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string pagePath = GetPagePath(filterContext);
            if (pagePath.IsNullOrWhiteSpace())
            {
#if DEBUG
                throw new Exception("'CurrentPagePath' is empty, please include @Html.HiddenForCurrentPagePath() in your form.");
#else
                filterContext.Result = new BadRequestResult();
                return;
#endif
            }
            base.OnActionExecuting(filterContext);
        }
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (filterContext.Result is ViewResult viewResult)
            {
                if (filterContext.ModelState.IsValid)
                {
                    RedirectToRefererPage(filterContext);
                }
                else
                {
                    RenderRefererPage(filterContext, viewResult);
                }
            }

        }
后面还有 17 行代码,解锁后查看完整代码

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

AI 解读 AI

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

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