From 5a7936034ead831cdf69cdae3e46f8170516efc6 Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期一, 22 十二月 2025 18:13:06 +0800
Subject: [PATCH] 1.组织架构增加是否末道工序报工字段:islastreport 2.报工调整增加工序编码查询字段:stepcode 3.报工调整增加批量改价接口 4.SOP上传增加文件大小校验

---
 VueWebCoreApi/Startup.cs |   40 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/VueWebCoreApi/Startup.cs b/VueWebCoreApi/Startup.cs
index fe8ee5f..efb7974 100644
--- a/VueWebCoreApi/Startup.cs
+++ b/VueWebCoreApi/Startup.cs
@@ -128,13 +128,21 @@
             //允许上传大文件
             services.Configure<IISServerOptions>(options =>
             {
-                options.MaxRequestBodySize = 1073741824;//此处限制最大1G  
+                options.MaxRequestBodySize = 10485760;//此处限制最大10M   
+            });
+            services.Configure<KestrelServerOptions>(options =>
+            {
+                options.Limits.MaxRequestBodySize = 10485760; // 10M
             });
             //解决文件上传Multipart body length limit 134217728 exceeded.
             services.Configure<FormOptions>(x =>
             {
+                //// 设置单个表单值的最大长度
                 x.ValueLengthLimit = int.MaxValue;
-                x.MultipartBodyLengthLimit = 1073741824; //此处限制最大1G  
+                // 设置多部分标头的长度限制
+                x.MultipartHeadersLengthLimit = int.MaxValue;
+                //设置整个 multipart 表单的最大长度(关键设置)
+                x.MultipartBodyLengthLimit = 10485760; //此处限制最大10M  
             });
             #endregion 允许大文件上传
         }
@@ -183,6 +191,34 @@
                 }
             });
             app.UseStaticFiles();
+            app.Use(async (context, next) =>
+            {
+                context.Request.EnableBuffering(); // 确保请求可以被多次读取
+                await next();
+            });
+            // 设置请求体大小限制
+            app.Use(async (context, next) =>
+            {
+                if (context.Request.ContentLength > 10 * 1024 * 1024) // 10MB
+                {
+                    var message = new ToMessage
+                    {
+                        code = "300",
+                        message = "请求体过大,请检查文件大小。"
+                    };
+
+                    // 设置正确的状态码并返回序列化后的JSON
+                    context.Response.StatusCode = 300; // 使用 413 Request Entity Too Large
+                    context.Response.ContentType = "application/json; charset=utf-8"; // 明确内容类型
+
+                    // 将对象序列化为JSON字符串
+                    string jsonResponse = System.Text.Json.JsonSerializer.Serialize(message);
+                    await context.Response.WriteAsync(jsonResponse);
+
+                    return; // 重要:直接返回,不再调用后续中间件
+                }
+                await next(); // 如果未超限,则继续执行管道中的下一个中间件
+            });
             //跨域
             app.UseCors("cors");
             //用户session服务

--
Gitblit v1.9.3