diff --git a/94_HttpModule.Proxy.Core/HttpModule.Proxy.Core/HttpModule.Proxy.Core.sln b/94_HttpModule.Proxy.Core/HttpModule.Proxy.Core/HttpModule.Proxy.Core.sln new file mode 100644 index 0000000..aecea8a --- /dev/null +++ b/94_HttpModule.Proxy.Core/HttpModule.Proxy.Core/HttpModule.Proxy.Core.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31624.102 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpModule.Proxy.Core", "HttpModule.Proxy.Core\HttpModule.Proxy.Core.csproj", "{C070FB18-9DA3-4EA6-A69C-AE0D25AD8617}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C070FB18-9DA3-4EA6-A69C-AE0D25AD8617}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C070FB18-9DA3-4EA6-A69C-AE0D25AD8617}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C070FB18-9DA3-4EA6-A69C-AE0D25AD8617}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C070FB18-9DA3-4EA6-A69C-AE0D25AD8617}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A67D4C98-498C-424B-83DB-E41D588C994F} + EndGlobalSection +EndGlobal diff --git a/94_HttpModule.Proxy.Core/HttpModule.Proxy.Core/HttpModule.Proxy.Core/HttpModule.Proxy.Core.csproj b/94_HttpModule.Proxy.Core/HttpModule.Proxy.Core/HttpModule.Proxy.Core/HttpModule.Proxy.Core.csproj new file mode 100644 index 0000000..f208d30 --- /dev/null +++ b/94_HttpModule.Proxy.Core/HttpModule.Proxy.Core/HttpModule.Proxy.Core/HttpModule.Proxy.Core.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/94_HttpModule.Proxy.Core/HttpModule.Proxy.Core/HttpModule.Proxy.Core/MyActionFilter.cs b/94_HttpModule.Proxy.Core/HttpModule.Proxy.Core/HttpModule.Proxy.Core/MyActionFilter.cs new file mode 100644 index 0000000..19e7cec --- /dev/null +++ b/94_HttpModule.Proxy.Core/HttpModule.Proxy.Core/HttpModule.Proxy.Core/MyActionFilter.cs @@ -0,0 +1,40 @@ +using System; + +namespace HttpModule.Proxy.Core +{ + public class MyActionFilter : IAsyncActionFilter + { + public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) + { + //============== 这里是执行方法之前获取数据 ==================== + // 获取控制器、路由信息 + var actionDescriptor = context.ActionDescriptor as ControllerActionDescriptor; + // 获取请求的方法 + var method = actionDescriptor!.MethodInfo; + // 获取 HttpContext 和 HttpRequest 对象 + var httpContext = context.HttpContext; + var httpRequest = httpContext.Request; + // 获取客户端 Ipv4 地址 + var remoteIPv4 = httpContext.GetRemoteIpAddressToIPv4(); + // 获取请求的 Url 地址 + var requestUrl = httpRequest.GetRequestUrlAddress(); + // 获取来源 Url 地址 + var refererUrl = httpRequest.GetRefererUrlAddress(); + // 获取请求参数(写入日志,需序列化成字符串后存储),可以自由篡改!!!!!! + var parameters = context.ActionArguments; + // 获取操作人(必须授权访问才有值)"userId" 为你存储的 claims type,jwt 授权对应的是 payload 中存储的键名 + var userId = httpContext.User?.FindFirstValue("userId"); + // 请求时间 + var requestedTime = DateTimeOffset.Now; + //============== 这里是执行方法之后获取数据 ==================== + var actionContext = await next(); + // 获取返回的结果 + var returnResult = actionContext.Result; + // 判断是否请求成功,没有异常就是请求成功 + var isRequestSucceed = actionContext.Exception == null; + // 获取调用堆栈信息,提供更加简单明了的调用和异常堆栈 + var stackTrace = EnhancedStackTrace.Current(); + // 其他操作,如写入日志 + } + } +} diff --git a/94_wai/Getf.Service.Transfer.Core/Session.cs b/94_wai/Getf.Service.Transfer.Core/Session.cs index 05a3fa1..e69426c 100644 --- a/94_wai/Getf.Service.Transfer.Core/Session.cs +++ b/94_wai/Getf.Service.Transfer.Core/Session.cs @@ -8,74 +8,78 @@ using System.Text; namespace Getf.Service.Transfer.Core { - public class Session : AppSession - { - static ArraySegment Heart = new ArraySegment(new byte[] { 0x40, 0x40, 0, 0, 0, 0, 0, 0, 0, 0 }); - protected override int GetMaxRequestLength() - { - return 100 * 1024 * 1024; - } + public class Session : AppSession + { + static ArraySegment Heart = new ArraySegment(new byte[] { 0x40, 0x40, 0, 0, 0, 0, 0, 0, 0, 0 }); + protected override int GetMaxRequestLength() + { + return 100 * 1024 * 1024; + } - protected override void OnSessionStarted() - { - base.OnSessionStarted(); - Logger.Debug("SessionStarted:" + this.SessionID); - } + protected override void OnSessionStarted() + { + base.OnSessionStarted(); + Logger.Debug("SessionStarted:" + this.SessionID); + } - public void SendHeart() - { - base.Send(Heart); - } + public void SendHeart() + { + base.Send(Heart); + } - /// - /// 异常捕捉 - /// - /// - protected override void HandleException(Exception e) - { - Logger.Error(e.Message, e); - base.HandleException(e); - } + /// + /// 异常捕捉 + /// + /// + protected override void HandleException(Exception e) + { + Logger.Error(e.Message, e); + base.HandleException(e); + } - protected override void HandleUnknownRequest(TransInfo requestInfo) - { - Logger.Warn("UnknownRequest" + JsonConvert.SerializeObject(requestInfo)); - base.HandleUnknownRequest(requestInfo); - } + protected override void HandleUnknownRequest(TransInfo requestInfo) + { + Logger.Warn("UnknownRequest" + JsonConvert.SerializeObject(requestInfo)); + base.HandleUnknownRequest(requestInfo); + } - public void Send(object entity) - { - List bufferHead = new List(); - bufferHead.AddRange(Encoding.UTF8.GetBytes("@@")); - List bufferBody = new List(); - //bufferBody.AddRange(new Guid(this.Key).ToByteArray()); - var json = JsonConvert.SerializeObject(entity); - bufferBody.AddRange(Encoding.UTF8.GetBytes(json)); - bufferHead.AddRange(BitConverter.GetBytes(bufferBody.Count)); - bufferHead.AddRange(BitConverter.GetBytes(0)); - bufferHead.AddRange(bufferBody); - ArraySegment arraySegment = new ArraySegment(bufferHead.ToArray()); - base.Send(arraySegment); - } + public void Send(object entity) + { + List bufferHead = new List(); + bufferHead.AddRange(Encoding.UTF8.GetBytes("@@")); + List bufferBody = new List(); + //bufferBody.AddRange(new Guid(this.Key).ToByteArray()); + var json = JsonConvert.SerializeObject(entity); + bufferBody.AddRange(Encoding.UTF8.GetBytes(json)); + bufferHead.AddRange(BitConverter.GetBytes(bufferBody.Count)); + bufferHead.AddRange(BitConverter.GetBytes(0)); + bufferHead.AddRange(bufferBody); + ArraySegment arraySegment = new ArraySegment(bufferHead.ToArray()); + base.Send(arraySegment); + } - public void Send(TransInfo transInfo) - { - List bufferHead = new List(); - bufferHead.AddRange(Encoding.UTF8.GetBytes("@@")); - List bufferBody = new List(); - //bufferBody.AddRange(new Guid(this.Key).ToByteArray()); - var json = JsonConvert.SerializeObject(transInfo); - bufferBody.AddRange(Encoding.UTF8.GetBytes(json)); - bufferHead.AddRange(BitConverter.GetBytes(bufferBody.Count)); - bufferHead.AddRange(BitConverter.GetBytes(transInfo.Data == null ? 0 : transInfo.Data.Length)); - bufferHead.AddRange(bufferBody); - if (transInfo.Data != null) - { - bufferHead.AddRange(transInfo.Data); - } - ArraySegment arraySegment = new ArraySegment(bufferHead.ToArray()); - base.Send(arraySegment); - } - } + public void Send(TransInfo transInfo) + { + if (transInfo.TransResultInfo == null) + transInfo.TransResultInfo = new TransResult { Code = 200 }; + else + transInfo.TransResultInfo.Code = 200; + List bufferHead = new List(); + bufferHead.AddRange(Encoding.UTF8.GetBytes("@@")); + List bufferBody = new List(); + //bufferBody.AddRange(new Guid(this.Key).ToByteArray()); + var json = JsonConvert.SerializeObject(transInfo); + bufferBody.AddRange(Encoding.UTF8.GetBytes(json)); + bufferHead.AddRange(BitConverter.GetBytes(bufferBody.Count)); + bufferHead.AddRange(BitConverter.GetBytes(transInfo.Data == null ? 0 : transInfo.Data.Length)); + bufferHead.AddRange(bufferBody); + if (transInfo.Data != null) + { + bufferHead.AddRange(transInfo.Data); + } + ArraySegment arraySegment = new ArraySegment(bufferHead.ToArray()); + base.Send(arraySegment); + } + } } diff --git a/94_wai/Getf.Service.Transfer.WinService/Getf.Service.Transfer.WinService.csproj b/94_wai/Getf.Service.Transfer.WinService/Getf.Service.Transfer.WinService.csproj index 1436d17..27742db 100644 --- a/94_wai/Getf.Service.Transfer.WinService/Getf.Service.Transfer.WinService.csproj +++ b/94_wai/Getf.Service.Transfer.WinService/Getf.Service.Transfer.WinService.csproj @@ -12,6 +12,7 @@ 512 true + false publish\ true Disk @@ -24,7 +25,6 @@ true 0 1.0.0.%2a - false false true diff --git a/94_wai/Getf.Service.Transfer/Getf.Service.Transfer.csproj b/94_wai/Getf.Service.Transfer/Getf.Service.Transfer.csproj index 568e715..ccf2b9c 100644 --- a/94_wai/Getf.Service.Transfer/Getf.Service.Transfer.csproj +++ b/94_wai/Getf.Service.Transfer/Getf.Service.Transfer.csproj @@ -11,6 +11,21 @@ v4.0 512 true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -85,5 +100,12 @@ PreserveNewest + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file