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 879b3c4c..3386af75 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 @@ -24,7 +24,7 @@ namespace Yi.Framework.Rbac.Application.Services.Authentication YiCrudAppService, IAuthService { - private HttpContext HttpContext { get; set; } + private HttpContext? HttpContext { get; set; } private ILogger _logger; private ISqlSugarRepository _repository; private IAccountManager _accountManager; @@ -33,7 +33,8 @@ namespace Yi.Framework.Rbac.Application.Services.Authentication ILogger logger, ISqlSugarRepository repository) : base(repository) { _logger = logger; - HttpContext = httpContextAccessor.HttpContext ?? throw new ApplicationException("未注册Http"); + //可能为空 + HttpContext = httpContextAccessor.HttpContext; _repository = repository; _accountManager = accountManager; } @@ -87,6 +88,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) {