添加项目文件。
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using Common;
|
||||
using CommonInfrastructure.Response;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
namespace CommonInfrastructure
|
||||
{
|
||||
public class BaseController : Controller
|
||||
{
|
||||
public LoginUser loginUser { get; set; }
|
||||
|
||||
public override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
var context = filterContext.HttpContext;
|
||||
|
||||
loginUser = new LoginUser();
|
||||
var request = context.Request;
|
||||
try
|
||||
{
|
||||
loginUser.UserId = context.User.Claims.FirstOrDefault(e => e.Type == "uid")?.Value;
|
||||
loginUser.UserName = context.User.Claims.FirstOrDefault(e => e.Type == "uname")?.Value;
|
||||
loginUser.DisplayName = context.User.Claims.FirstOrDefault(e => e.Type == "dname")?.Value;
|
||||
loginUser.Icon = context.User.Claims.FirstOrDefault(e => e.Type == "avatar")?.Value;
|
||||
loginUser.Number = context.User.Claims.FirstOrDefault(e => e.Type == "number")?.Value;
|
||||
|
||||
loginUser.Ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault()?.Split(',').FirstOrDefault()?.Trim();
|
||||
|
||||
if (string.IsNullOrEmpty(loginUser.Ip))
|
||||
{
|
||||
loginUser.Ip = context.Connection.RemoteIpAddress?.ToString() ?? "";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
filterContext.Result = new JsonResult(new BaseCommonResponse() { Code = CommonResponseCodeEnum.ParamError, Info = "请求参数异常"+ex.Message });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user