From 84cd83894b3ec614250cdf25ef7c187ce5efbe17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Sat, 16 Nov 2024 11:07:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dauthservice=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Authentication/AuthService.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/Authentication/AuthService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/Authentication/AuthService.cs index ecdbf68c..312bdba3 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/Authentication/AuthService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/Authentication/AuthService.cs @@ -20,14 +20,15 @@ namespace Yi.Framework.Rbac.Application.Services.Authentication /// public class AuthService : YiCrudAppService { - private HttpContext HttpContext { get; set; } + private HttpContext? HttpContext { get; set; } private ILogger _logger; private ISqlSugarRepository _repository; private IAccountManager _accountManager; public AuthService(IAccountManager accountManager, IHttpContextAccessor httpContextAccessor, ILogger logger, ISqlSugarRepository repository) : base(repository) { _logger = logger; - HttpContext = httpContextAccessor.HttpContext ?? throw new ApplicationException("未注册Http"); + //可能为空 + HttpContext = httpContextAccessor.HttpContext; _repository = repository; _accountManager = accountManager; } @@ -79,6 +80,10 @@ namespace Yi.Framework.Rbac.Application.Services.Authentication private async Task<(string, string)> GetOpenIdAndNameAsync(string scheme) { + if (HttpContext is null) + { + throw new AggregateException("HttpContext 参数为空"); + } var authenticateResult = await HttpContext.AuthenticateAsync(scheme); if (!authenticateResult.Succeeded) {