kuayu
build / build-push (push) Successful in 31s

This commit is contained in:
wanghu
2026-09-03 12:06:08 +08:00
parent 262f0da9c2
commit 02a752ad87
2 changed files with 35 additions and 4 deletions
@@ -53,9 +53,19 @@ namespace YhCore.WebApi.Middleware
timeNow = TimeNow() timeNow = TimeNow()
}); });
} }
catch (Exception) catch (Exception ex)
{ {
// 未捕获异常 → 平台兜底:200 + code:6 内部服务错误(对齐 Java GlobalExceptionHandler.handleException) // 未捕获异常 → 平台兜底:200 + code:6 内部服务错误(对齐 Java GlobalExceptionHandler.handleException)
// [TEMP-DIAG 2026-09-03] 完整堆栈落 api-access 日志,定位 GetUserInfo code6 根因后移除
try
{
log4net.LogManager.GetLogger(typeof(GlobalExceptionMiddleware))
.Error("UNCAUGHT-EXCEPTION url=" + context.Request.Path + context.Request.QueryString + " => " + ex);
}
catch
{
// 诊断日志失败不影响响应
}
await WriteJsonAsync(context, StatusCodes.Status200OK, new await WriteJsonAsync(context, StatusCodes.Status200OK, new
{ {
code = ErrorCode.InternalServerError.Code, code = ErrorCode.InternalServerError.Code,
+24 -3
View File
@@ -116,6 +116,20 @@ namespace YhCore.WebApi
// Redis 缓存(RedisUtil 单例,连接串取 Redis:ConnectionString) // Redis 缓存(RedisUtil 单例,连接串取 Redis:ConnectionString)
services.AddRedisCache(Configuration); services.AddRedisCache(Configuration);
// ===== 会话状态(Session)=====
// 对应 Java HttpSession / session.invalidate();旧 DocPrintCore 同款配置。
// 注意:YhAuth 的登录态走自定义短 Cookie(SessionTicketDataFormat,票据存进程内存),
// 这里的 ASP.NET Core Session 仅用于 Logout 时 HttpContext.Session.Clear() 释放会话级数据,
// 与认证 Cookie 相互独立(各自独立 Cookie)。
// 使用进程内分布式缓存(单实例);多实例部署请改用 Redis 支撑的 IDistributedCache。
services.AddDistributedMemoryCache();
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(20);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
// 审计日志查询(sys_operation_log 分页搜索,LogServiceStub 已被真实实现替换) // 审计日志查询(sys_operation_log 分页搜索,LogServiceStub 已被真实实现替换)
services.AddScoped<ILogService, LogService>(); services.AddScoped<ILogService, LogService>();
@@ -177,9 +191,6 @@ namespace YhCore.WebApi
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
// 对应 Java @CrossOrigin(originPatterns={"*"}, allowCredentials="true")
app.UseCors("default");
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(c => app.UseSwaggerUI(c =>
{ {
@@ -191,6 +202,16 @@ namespace YhCore.WebApi
// 管道顺序:先路由,再认证;CAS 回调必须在认证阶段消费 ticket 并写入 Cookie。 // 管道顺序:先路由,再认证;CAS 回调必须在认证阶段消费 ticket 并写入 Cookie。
app.UseRouting(); app.UseRouting();
// CORS 中间件必须位于 UseRouting 之后、UseEndpoints 之前(endpoint-aware 模式):
// 否则带 [EnableCors] 元数据的控制器端点执行时抛 InvalidOperationException
// "contains CORS metadata, but a middleware was not found that supports CORS"(曾导致 GetUserInfo code6)。
// 对应 Java @CrossOrigin(originPatterns={"*"}, allowCredentials="true")
app.UseCors("default");
// 启用 ASP.NET Core Session(需在 UseEndpoints 之前、且在使用 Session 的组件之前注册)。
// 仅 Logout 真正读写;其余请求不触碰 Session,不会额外下发 .AspNetCore.Session Cookie。
app.UseSession();
app.UseMiddleware<ApiAccessLogMiddleware>(); // 0. 接口访问日志(唯一日志出口) app.UseMiddleware<ApiAccessLogMiddleware>(); // 0. 接口访问日志(唯一日志出口)
app.UseMiddleware<GlobalExceptionMiddleware>(); // 1. 异常兜底(异常摘要并入接口日志) app.UseMiddleware<GlobalExceptionMiddleware>(); // 1. 异常兜底(异常摘要并入接口日志)
app.UseAuthentication(); // 2. CAS ticket 校验 + Cookie 恢复(Yh.Platform.Auth) app.UseAuthentication(); // 2. CAS ticket 校验 + Cookie 恢复(Yh.Platform.Auth)