using System; using System.Collections.Generic; using System.Text; using NP.Base.ENUM; using System.Security.Claims; using System.Web.Mvc; using System.Linq; namespace NP.Base.Auth { public class AFilter : ActionFilterAttribute { public EMRole[] Roles { get; set; } BaseController _base; public bool IsFront { get; set; } public override void OnActionExecuting(ActionExecutingContext context) { Controller currentControll = context.Controller as Controller; _base = currentControll as BaseController; if (!IsFront) { var cm = _base.GetMENUS .Where(w => w.usertype == _base.SUserInfo.UserType && w.menuurl.Equals(context.HttpContext.Request.Url.AbsolutePath)) .OrderByDescending(od => od.menulevel) .FirstOrDefault(); var absolutePath = context.HttpContext.Request.Url.AbsolutePath.ToLower(); if (cm != null || (_base.SUserInfo.UserNo > 0 && (absolutePath == "/" || absolutePath.StartsWith("/home")))) { _base.ViewBag.Title = (cm ?? new Model.Menu()).menuname ?? "Home"; _base.ViewBag.CMenu = cm; _base.ViewBag.CMenuNo = (cm ?? new Model.Menu()).menuno; _base.ViewBag.CHidden = (cm ?? new Model.Menu()).ishid; var pmenu = (_base.GetMENUS.Where(w => w.menuno == (cm ?? new Model.Menu()).pmenuno).FirstOrDefault() ?? new Model.Menu()); _base.ViewBag.pmenuno = pmenu.ishid == 1 ? pmenu.pmenuno : pmenu.menuno; _base.ViewBag.pmenunos = (cm ?? new Model.Menu()).menurout; // 접속로그 (2025-04-14 HS: 불필요한 2중 Task제거 후 await 구문으로 변경) var rtn = System.Threading.Tasks.Task.Run(async () => await _base.Dao.Log( new Model.PageLog() { uno = _base.SUserInfo.UserNo, uip = _base.GetUserIP(), logsite = 0, menuno = _base.ViewBag.CMenuNo < 1 ? (int?)null : _base.ViewBag.CMenuNo, loginfo = _base.ViewBag.Title }) ); base.OnActionExecuting(context); } else { context.Result = new RedirectResult("/Account/Index?returnUrl=" + context.HttpContext.Request.Path.ToString() + context.HttpContext.Request.QueryString); } } else { var ap = context.HttpContext.Request.Url.AbsolutePath.ToUpper(); if (_base.SUserInfo.UserNo > 0) { base.OnActionExecuting(context); } else { context.Result = new RedirectResult("/Account/Index?returnUrl=" + context.HttpContext.Request.Path.ToString() + context.HttpContext.Request.QueryString); } } } public static EMRole GetEMRole(int userType) { switch (userType) { case 99: return EMRole.Admin; case 1: return EMRole.Student; } return EMRole.Anonymous; } } }