减少TraceItem数据量较大时的性能浪费
智能大石头 authored at 2024-10-22 08:41:14
724.00 B
Stardust
using System;
using Microsoft.AspNetCore.Mvc.Filters;
using NewLife;
using NewLife.Remoting;
using Stardust.Server.Controllers;

namespace Stardust.Server.Common
{
    /// <summary>令牌校验</summary>
    public class TokenFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            if (context.Controller is BaseController bc)
            {
                var session = bc.Session;
                if (bc.Token.IsNullOrEmpty()) throw new ApiException(403, "未授权");
                if (session == null) throw new ApiException(402, "令牌无效");
            }

            base.OnActionExecuting(context);
        }
    }
}