mh_frame_sps/APT.Infrastructure.Api/Extensions/RootOrgAttribute.cs

44 lines
1.3 KiB
C#
Raw Permalink Normal View History

2026-04-07 13:47:52 +08:00
using APT.Infrastructure.Core;
using log4net;
using Microsoft.AspNetCore.Mvc.Filters;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace APT.Infrastructure.Api
{
public class RootOrgAttribute : Attribute, IAsyncActionFilter
{
/// <summary>
/// 添加根节点过滤
/// </summary>
/// <param name="context"></param>
/// <param name="next"></param>
/// <returns></returns>
public async Task OnActionExecutionAsync(Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext context, ActionExecutionDelegate next)
{
try
{
var s = context.HttpContext.Request.Headers["RootOrgId"].ToString();
if (!string.IsNullOrEmpty(s))
{
AppContext.CurrentSession.RootOrgId = new Guid(s);
}
}
catch (Exception ex)
{
LoggerManager.GetLogger().Error(Infrastructure.Core.LogHelper.GetCurSourceFileName() + " - " + LogHelper.GetLineNum() + ":" + ex.Message);
//throw;
}
finally
{
await next.Invoke();
}
}
}
}