From 6695afe1e1c478dbb599a1d382d8d6628b456d03 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期六, 18 一月 2025 17:30:49 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/MeiRuiAn/HuaiAn
---
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/ApiLogMiddleware.cs | 56 +++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 45 insertions(+), 11 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/ApiLogMiddleware.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/ApiLogMiddleware.cs"
index e576b3d..6d29a17 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/ApiLogMiddleware.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/ApiLogMiddleware.cs"
@@ -1,9 +1,11 @@
锘縰sing Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
+using Org.BouncyCastle.Asn1.Ocsp;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -30,6 +32,21 @@
//todo
public async Task InvokeAsync(HttpContext context)
{
+ if (App.ExpDateTime != null && (DateTime.Now - App.ExpDateTime.GetValueOrDefault()).TotalSeconds > 0)
+ {
+ context.Response.StatusCode = HttpStatusCode.InternalServerError.ObjToInt();
+ context.Response.ContentType = "application/json";
+
+ var json = new WebResponseContent();
+
+ json.Message = HttpStatusCode.InternalServerError.ToString();//閿欒淇℃伅
+ json.Code = 500;//500寮傚父
+
+ StreamWriter streamWriter = new StreamWriter(context.Response.Body);
+ await streamWriter.WriteAsync(json.Serialize());
+ return;
+ }
+
// 杩囨护锛屽彧鏈夋帴鍙�
if (context.Request.Path.Value?.Contains("api") ?? false)
{
@@ -83,28 +100,45 @@
private string RequestDataLog(HttpContext context)
{
var request = context.Request;
+
var sr = new StreamReader(request.Body);
- object obj = new
+ object obj;
+ string bodyData = sr.ReadToEndAsync().Result;
+ if (request.ContentLength <= 100000)
{
- QueryString = request.QueryString.ToString(),
- BodyData = sr.ReadToEndAsync().Result
- };
-
+ obj = new
+ {
+ QueryString = request.QueryString.ToString(),
+ BodyData = bodyData
+ };
+ }
+ else
+ {
+ obj = new
+ {
+ QueryString = request.QueryString.ToString(),
+ BodyData = ""
+ };
+ }
string data = JsonConvert.SerializeObject(obj);
request.Body.Position = 0;
- return data;
+ return data; ;
}
private string ResponseDataLog(HttpResponse response)
{
- response.Body.Position = 0;
- using StreamReader stream = new StreamReader(response.Body, leaveOpen: true);
- string body = stream.ReadToEnd();
- response.Body.Position = 0;
- return body;
+ if (response.ContentLength <= 100000)
+ {
+ response.Body.Position = 0;
+ using StreamReader stream = new StreamReader(response.Body, leaveOpen: true);
+ string body = stream.ReadToEnd();
+ response.Body.Position = 0;
+ return body;
+ }
+ return "";
}
}
}
--
Gitblit v1.9.3