@@ -116,6 +116,20 @@ namespace YhCore.WebApi
|
||||
// Redis 缓存(RedisUtil 单例,连接串取 Redis:ConnectionString)
|
||||
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 已被真实实现替换)
|
||||
services.AddScoped<ILogService, LogService>();
|
||||
|
||||
@@ -177,9 +191,6 @@ namespace YhCore.WebApi
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
// 对应 Java @CrossOrigin(originPatterns={"*"}, allowCredentials="true")
|
||||
app.UseCors("default");
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
@@ -191,6 +202,16 @@ namespace YhCore.WebApi
|
||||
// 管道顺序:先路由,再认证;CAS 回调必须在认证阶段消费 ticket 并写入 Cookie。
|
||||
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<GlobalExceptionMiddleware>(); // 1. 异常兜底(异常摘要并入接口日志)
|
||||
app.UseAuthentication(); // 2. CAS ticket 校验 + Cookie 恢复(Yh.Platform.Auth)
|
||||
|
||||
Reference in New Issue
Block a user