token 验证

This commit is contained in:
yanghongwei 2025-04-02 23:30:37 +08:00
parent dedaf3e0a3
commit 41dde067d2
1 changed files with 32 additions and 23 deletions

View File

@ -12,6 +12,8 @@ namespace LY.App.MiddleWare
_redis = redisHelper; _redis = redisHelper;
} }
public async Task InvokeAsync(HttpContext context, RequestDelegate next) public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
try
{ {
// 排除不需要Token验证的API // 排除不需要Token验证的API
if (IsExcludedPath(context.Request.Path)) if (IsExcludedPath(context.Request.Path))
@ -49,6 +51,13 @@ namespace LY.App.MiddleWare
await context.Response.WriteAsync("Unauthorized: Invalid Token"); await context.Response.WriteAsync("Unauthorized: Invalid Token");
} }
} }
catch (Exception ex)
{
context.Response.StatusCode = 401;
await context.Response.WriteAsync("Unauthorized: Invalid Token");
}
}
/// <summary> /// <summary>
/// 这是放不需要过滤的api地址 /// 这是放不需要过滤的api地址
/// </summary> /// </summary>