public async Task SendToUsersAsync<T>(T message) where T : SigalRMessage
{
try
{
if (!message.UserIds.HasItems())
return;
var stringUserIds = message.UserIds.Where(s => !s.IsNullOrEmpty()).Select(x => x.Value.ToString()).ToList();
await _hubContext.Clients.Users(stringUserIds).SendAsync(message.MessageType.ToString(), message);
}
catch (Exception ex)
{
_logger.LogError(ex, "error");
}
}
protected override async Task OnInitializedAsync()
{
SetTableOption();
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;
var claims = CurrentUser.GetAllClaims();
var headers = new Dictionary<string, string>();
foreach (var claim in claims)
{
if (!headers.Keys.Contains(claim.Type))
headers.Add(claim.Type, claim.Value);
}
_userToken = user.FindFirstValue("access_token");
var signalRUrl = "wss://localhost:44320".EnsureEndsWith('/') + Configuration["HubUrl"].TrimStart('/');
HubConnection = new HubConnectionBuilder()
.WithUrl(signalRUrl, options =>
{
options.Headers = headers;
options.AccessTokenProvider = () => Task.FromResult(_userToken);
}).WithAutomaticReconnect().Build();
// 2. 定义客户端方法以接收服务器消息
HubConnection.On<SigalRMessage<Dictionary<string, string>>>(SigalRMessageTypeEnum.OrderSyncSuccess.ToString(), async message =>
{
await JSRuntime.InvokeVoidAsync("console.log", $"收到sigalr消息:{message.ToJson()} {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
StateHasChanged();
});
await HubConnection.StartAsync();
}
I looked at some sample code
[Inject]
protected IAbpAccessTokenProvider AccessTokenProvider { get; set; }
[Inject]
protected IOptions<ChatBlazorMauiBlazorOptions> ChatBlazorMauiBlazorOptions { get; set; }
[Inject]
protected IOptions<AbpRemoteServiceOptions> AbpRemoteServiceOptions { get; set; }
protected async override Task SetChatHubConnectionAsync()
{
var accessToken = await AccessTokenProvider.GetTokenAsync();
var signalrUrl = ChatBlazorMauiBlazorOptions.Value.SignalrUrl ?? AbpRemoteServiceOptions.Value.RemoteServices.Default.BaseUrl;
HubConnection = new HubConnectionBuilder()
.WithUrl(signalrUrl.EnsureEndsWith('/') + "signalr-hubs/chat", options =>
{
options.AccessTokenProvider = () => Task.FromResult(accessToken);
})
.Build();
}
But IAbpAccessTokenProvider does not seem to exist in abp7.2.3 version
Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, and please first use the search on the homepage. Provide us with the following info:
ABP Framework version: v7.2.3
UI Type: Blazor Server
Database System: EF Core (SQL Server)
Tiered (for MVC) or Auth Server Separated (for Angular): yes
Exception message and full stack trace:2024-02-05 16:25:32.378 +08:00 [ERR] Unauthorized
Volo.Abp.Http.Client.AbpRemoteCallException: Unauthorized
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.ThrowExceptionForResponseAsync(HttpResponseMessage response) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync(ClientProxyRequestContext requestContext)
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.RequestAsync[T](ClientProxyRequestContext requestContext) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
at Volo.Abp.Identity.IdentityUserClientProxy.GetAssignableRolesAsync()
at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.UserManagement.OnInitializedAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
2024-02-05 16:25:32.378 +08:00 [ERR] 执行异常处理逻辑,HttpStatusCode--401,Message--Unauthorized
2024-02-05 16:25:32.378 +08:00 [ERR] 执行异常处理401过期,HttpStatusCode--401,Message--Unauthorized
2024-02-05 16:25:32.378 +08:00 [WRN] Unhandled exception rendering component: Unauthorized
Volo.Abp.Http.Client.AbpRemoteCallException: Unauthorized
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.ThrowExceptionForResponseAsync(HttpResponseMessage response) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync(ClientProxyRequestContext requestContext)
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.RequestAsync[T](ClientProxyRequestContext requestContext) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
at Volo.Abp.Identity.IdentityUserClientProxy.GetAssignableRolesAsync()
at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.UserManagement.OnInitializedAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
2024-02-05 16:25:32.378 +08:00 [ERR] Unauthorized
Volo.Abp.Http.Client.AbpRemoteCallException: Unauthorized
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.ThrowExceptionForResponseAsync(HttpResponseMessage response) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync(ClientProxyRequestContext requestContext)
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.RequestAsync[T](ClientProxyRequestContext requestContext) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
at Volo.Abp.Identity.OrganizationUnitClientProxy.GetListAllAsync()
at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.OrganizationUnitsManagement.GetOrganizationUnitsAsync()
at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.OrganizationUnitsManagement.OnInitializedAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
2024-02-05 16:25:32.379 +08:00 [ERR] 执行异常处理逻辑,HttpStatusCode--401,Message--Unauthorized
2024-02-05 16:25:32.379 +08:00 [ERR] 执行异常处理401过期,HttpStatusCode--401,Message--Unauthorized
2024-02-05 16:25:32.379 +08:00 [WRN] Unhandled exception rendering component: Unauthorized
Volo.Abp.Http.Client.AbpRemoteCallException: Unauthorized
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.ThrowExceptionForResponseAsync(HttpResponseMessage response) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync(ClientProxyRequestContext requestContext)
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.RequestAsync[T](ClientProxyRequestContext requestContext) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
at Volo.Abp.Identity.OrganizationUnitClientProxy.GetListAllAsync()
at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.OrganizationUnitsManagement.GetOrganizationUnitsAsync()
at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.OrganizationUnitsManagement.OnInitializedAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
2024-02-05 16:25:32.380 +08:00 [ERR] Unauthorized
Volo.Abp.Http.Client.AbpRemoteCallException: Unauthorized
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.ThrowExceptionForResponseAsync(HttpResponseMessage response) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync(ClientProxyRequestContext requestContext)
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.RequestAsync[T](ClientProxyRequestContext requestContext) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
at Volo.Abp.Identity.IdentityUserClientProxy.GetExternalLoginProvidersAsync()
at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.Components.IdentityUserImportDropdownComponent.OnInitializedAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
2024-02-05 16:25:32.380 +08:00 [ERR] 执行异常处理逻辑,HttpStatusCode--401,Message--Unauthorized
2024-02-05 16:25:32.380 +08:00 [ERR] 执行异常处理401过期,HttpStatusCode--401,Message--Unauthorized
2024-02-05 16:25:32.380 +08:00 [WRN] Unhandled exception rendering component: Unauthorized
Volo.Abp.Http.Client.AbpRemoteCallException: Unauthorized
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.ThrowExceptionForResponseAsync(HttpResponseMessage response) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync(ClientProxyRequestContext requestContext)
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.RequestAsync[T](ClientProxyRequestContext requestContext) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
at Volo.Abp.Identity.IdentityUserClientProxy.GetExternalLoginProvidersAsync()
at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.Components.IdentityUserImportDropdownComponent.OnInitializedAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
2024-02-05 16:25:32.380 +08:00 [INF] Received HTTP response headers after 64.4974ms - 401
2024-02-05 16:25:32.380 +08:00 [INF] End processing HTTP request after 64.705ms - 401
2024-02-05 16:25:32.380 +08:00 [ERR] Unauthorized
Volo.Abp.Http.Client.AbpRemoteCallException: Unauthorized
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.ThrowExceptionForResponseAsync(HttpResponseMessage response) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync(ClientProxyRequestContext requestContext)
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.RequestAsync[T](ClientProxyRequestContext requestContext) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
at Volo.Saas.Host.ClientProxies.EditionClientProxy.GetListAsync(GetEditionsInput input)
at Volo.Saas.Host.Blazor.Pages.Saas.Host.TenantManagement.OnInitializedAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
2024-02-05 16:25:32.380 +08:00 [ERR] 执行异常处理逻辑,HttpStatusCode--401,Message--Unauthorized
2024-02-05 16:25:32.380 +08:00 [ERR] 执行异常处理401过期,HttpStatusCode--401,Message--Unauthorized
2024-02-05 16:25:32.380 +08:00 [WRN] Unhandled exception rendering component: Unauthorized
Volo.Abp.Http.Client.AbpRemoteCallException: Unauthorized
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.ThrowExceptionForResponseAsync(HttpResponseMessage response) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync(ClientProxyRequestContext requestContext)
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.RequestAsync[T](ClientProxyRequestContext requestContext) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
at Volo.Saas.Host.ClientProxies.EditionClientProxy.GetListAsync(GetEditionsInput input)
at Volo.Saas.Host.Blazor.Pages.Saas.Host.TenantManagement.OnInitializedAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
2024-02-05 16:25:32.381 +08:00 [ERR] Unauthorized
Volo.Abp.Http.Client.AbpRemoteCallException: Unauthorized
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.ThrowExceptionForResponseAsync(HttpResponseMessage response) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync(ClientProxyRequestContext requestContext)
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.RequestAsync[T](ClientProxyRequestContext requestContext) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
at Volo.Abp.Identity.OrganizationUnitClientProxy.GetListAllAsync()
at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.OrganizationUnitsManagement.GetOrganizationUnitsAsync()
at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.OrganizationUnitsManagement.OnInitializedAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
2024-02-05 16:25:32.381 +08:00 [ERR] 执行异常处理逻辑,HttpStatusCode--401,Message--Unauthorized
2024-02-05 16:25:32.381 +08:00 [ERR] 执行异常处理401过期,HttpStatusCode--401,Message--Unauthorized
2024-02-05 16:25:32.381 +08:00 [WRN] Unhandled exception rendering component: Unauthorized
Volo.Abp.Http.Client.AbpRemoteCallException: Unauthorized
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.ThrowExceptionForResponseAsync(HttpResponseMessage response) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync(ClientProxyRequestContext requestContext)
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.RequestAsync[T](ClientProxyRequestContext requestContext) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
at Volo.Abp.Identity.OrganizationUnitClientProxy.GetListAllAsync()
at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.OrganizationUnitsManagement.GetOrganizationUnitsAsync()
at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.OrganizationUnitsManagement.OnInitializedAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
2024-02-05 16:25:32.382 +08:00 [ERR] Unauthorized
Volo.Abp.Http.Client.AbpRemoteCallException: Unauthorized
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.ThrowExceptionForResponseAsync(HttpResponseMessage response) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync(ClientProxyRequestContext requestContext)
at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase1.RequestAsync[T](ClientProxyRequestContext requestContext) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase
1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
at Volo.Abp.Identity.IdentityUserClientProxy.GetAssignableRolesAsync()
at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.UserManagement.OnInitializedAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
2024-02-05 16:25:32.382 +08:00 [ERR] 执行异常处理逻辑,HttpStatusCode--401,Message--Unauthorized
Steps to reproduce the issue:After staying on the page for a few hours, click the query button of the page again. The status is 401 but it will not jump to the login page. The page will keep flashing. AbpComponentsBase is not used, but a custom base class, in which the exception handling code:
` protected override async Task OnErrorAsync(Exception exception) { if (IsDisposed) return;
Logger.LogError(new EventId(0, "Global Exception"), exception: exception, message: exception.Message);
if (exception is AbpRemoteCallException)
{
var ex = exception as AbpRemoteCallException;
Logger.LogError($"Execute exception handling logic, HttpStatusCode--{ex.HttpStatusCode},Message--{ex.Message}");
//401 error returns to the original exception handling mechanism and allows the front desk to jump
if (ex.HttpStatusCode == (int)HttpStatusCode.Unauthorized)
{
Logger.LogError($"Execution exception handling 401 expired, HttpStatusCode--{ex.HttpStatusCode},Message--{ex.Message}");
await base.OnErrorAsync(exception);
return;
}
await UiMessageService.Info(ex.Error.Message, ex.Error.Code);
return;
}
//await base.OnErrorAsync(exception);
if (exception is UserFriendlyException)
{
var ex = exception as UserFriendlyException;
await UiMessageService.Info(ex.Message);
return;
}
if (exception is BusinessException)
{
var ex = exception as BusinessException;
await UiMessageService.Warn(ex.Message, ex.Code);
return;
}
await UiMessageService.Error(exception.Message);
}`
ABP Framework version: v7.2.3
UI Type: Blazor Server
Database System: EF Core
Tiered (for MVC) or Auth Server Separated (for Angular): yes
Exception message and full stack trace:
Steps to reproduce the issue: seems to be related to resource release.
Hello I am using LeptonXTheme UI. I want to be able to see which pages have been opened like the picture above. Display all open tabs at the top and click on the tab above to achieve the effect of switching pages. This is what I have here. A usage habit, does LeptonXTheme UI support this function? In addition, every time I open the page and return to the previous page, the page status will not be retained. Is it possible to maintain the page status like vue keep-alive or do A short-lived storage; now I cannot use LeptonXTheme UI to achieve the above functions. Can you give me some methods or suggestions to achieve these functions?
1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy
1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy1.CreateValue() at Loda.Abp.Components.LodaComponentBase.get_Logger() at Loda.Abp.Components.LodaComponentBase.OnErrorAsync(Exception exception) at Microsoft.AspNetCore.Components.ErrorBoundaryBase.Microsoft.AspNetCore.Components.IErrorBoundary.HandleException(Exception exception) at Microsoft.AspNetCore.Components.RenderTree.Renderer.HandleExceptionViaErrorBoundary(Exception error, ComponentState errorSourceOrNull) [18:21:47 ERR] Unhandled exception in circuit 'LIOY43OPH3utkSu22ZegyguiJKfC3kmBReCuWQ8lhY8'. System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Loda.Abp.StoreManage.Inventories.Blazor.Pages.Inventories.OutboundOrder'. at Loda.Abp.Components.LodaComponentBase.get_ScopedServices() at Loda.Abp.Components.LodaComponentBase.LazyGetRequiredService[TRef](Type serviceType, TRef& reference) at Loda.Abp.Components.LodaComponentBase.LazyGetRequiredService[TService](TService& reference) at Loda.Abp.Components.LodaComponentBase.get_LoggerFactory() at Loda.Abp.Components.LodaComponentBase.<get__lazyLogger>b__37_0() at System.Lazy
1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy
1.CreateValue()
at Loda.Abp.Components.LodaComponentBase.get_Logger()
at Loda.Abp.Components.LodaComponentBase.OnErrorAsync(Exception exception)
at Microsoft.AspNetCore.Components.ErrorBoundaryBase.Microsoft.AspNetCore.Components.IErrorBoundary.HandleException(Exception exception)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.HandleExceptionViaErrorBoundary(Exception error, ComponentState errorSourceOrNull)
[18:21:47 INF] Executed endpoint '/_blazor'
[18:21:47 INF] Request finished HTTP/2 CONNECT https://localhost:44354/_blazor?id=XaSAouEAb9hvCj8WlD56sA - - - 200 - - 5496.7929ms
[18:21:47 INF] Connection id "0HMVLFE759C7D", Request id "0HMVLFE759C7D:0000003B": the application completed without reading the entire request body.LodaComponentBase.cs,This is the base class for all our component pages
using Blazorise.Localization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Net;
using Volo.Abp;
using Volo.Abp.AspNetCore.Components.Alerts;
using Volo.Abp.AspNetCore.Components.ExceptionHandling;
using Volo.Abp.AspNetCore.Components.Messages;
using Volo.Abp.AspNetCore.Components.Notifications;
using Volo.Abp.Http.Client;
using Volo.Abp.Localization;
using Volo.Abp.MultiTenancy;
using Volo.Abp.ObjectMapping;
using Volo.Abp.Timing;
using Volo.Abp.Users;
namespace Loda.Abp.Components
{
public class LodaComponentBase : ErrorBoundary, IDisposable
{
[Inject] public IUiMessageService UiMessageService { get; set; }
[Inject]
public Blazorise.Localization.ITextLocalizerService LocalizationService { get; set; }
public LodaComponentBase()
{
}
protected override Task OnInitializedAsync()
{
var IetfLanguageTag = CultureInfo.CurrentCulture.IetfLanguageTag;
if (IetfLanguageTag.Split("-").Length > 1)
{
var split = IetfLanguageTag.Split("-")[0];
LocalizationService.ChangeLanguage(split);
}
return base.OnInitializedAsync();
}
protected override Task OnErrorAsync(Exception exception)
{
Logger.LogError(new EventId(0, "全局异常"), exception: exception, message: exception.Message);
if (exception is AbpRemoteCallException)
{
var ex = exception as AbpRemoteCallException;
//401错误返回原来的异常处理机制,让前台做跳转
if (ex.HttpStatusCode == (int)HttpStatusCode.Unauthorized) return base.OnErrorAsync(exception);
return UiMessageService.Info(ex.Error.Message, ex.Error.Code);
}
//await base.OnErrorAsync(exception);
if (exception is UserFriendlyException)
{
var ex = exception as UserFriendlyException;
return UiMessageService.Info(ex.Message);
}
if (exception is BusinessException)
{
var ex = exception as BusinessException;
return UiMessageService.Warn(ex.Message, ex.Code);
}
return UiMessageService.Error(exception.Message);
}
//OwningComponentBase 基类部分
private AsyncServiceScope? _scope;
[Inject] IServiceScopeFactory ScopeFactory { get; set; } = default!;
protected bool IsDisposed { get; private set; }
protected IServiceProvider ScopedServices
{
get
{
if (ScopeFactory == null)
{
throw new InvalidOperationException("Services cannot be accessed before the component is initialized.");
}
ObjectDisposedException.ThrowIf(IsDisposed, this);
_scope ??= ScopeFactory.CreateAsyncScope();
return _scope.Value.ServiceProvider;
}
}
void IDisposable.Dispose()
{
if (!IsDisposed)
{
_scope?.Dispose();
_scope = null;
Dispose(disposing: true);
IsDisposed = true;
}
}
/// <inheritdoc />
protected virtual void Dispose(bool disposing)
{
}
//---------------------------------------------
//AbpComponentBase基类部分
protected IStringLocalizerFactory StringLocalizerFactory => LazyGetRequiredService(ref _stringLocalizerFactory);
private IStringLocalizerFactory _stringLocalizerFactory;
protected IStringLocalizer L
{
get
{
if (_localizer == null)
{
_localizer = CreateLocalizer();
}
return _localizer;
}
}
private IStringLocalizer _localizer;
protected Type LocalizationResource
{
get => _localizationResource;
set
{
_localizationResource = value;
_localizer = null;
}
}
private Type _localizationResource = typeof(DefaultResource);
protected ILogger Logger => _lazyLogger.Value;
private Lazy<ILogger> _lazyLogger => new Lazy<ILogger>(() => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance, true);
protected ILoggerFactory LoggerFactory => LazyGetRequiredService(ref _loggerFactory);
private ILoggerFactory _loggerFactory;
protected IAuthorizationService AuthorizationService => LazyGetRequiredService(ref _authorizationService);
private IAuthorizationService _authorizationService;
protected ICurrentUser CurrentUser => LazyGetRequiredService(ref _currentUser);
private ICurrentUser _currentUser;
protected ICurrentTenant CurrentTenant => LazyGetRequiredService(ref _currentTenant);
private ICurrentTenant _currentTenant;
protected IUiMessageService Message => LazyGetNonScopedRequiredService(ref _message);
private IUiMessageService _message;
protected IUiNotificationService Notify => LazyGetNonScopedRequiredService(ref _notify);
private IUiNotificationService _notify;
protected IUserExceptionInformer UserExceptionInformer => LazyGetNonScopedRequiredService(ref _userExceptionInformer);
private IUserExceptionInformer _userExceptionInformer;
protected IAlertManager AlertManager => LazyGetNonScopedRequiredService(ref _alertManager);
private IAlertManager _alertManager;
protected IClock Clock => LazyGetNonScopedRequiredService(ref _clock);
private IClock _clock;
protected AlertList Alerts => AlertManager.Alerts;
protected IObjectMapper ObjectMapper
{
get
{
if (_objectMapper != null)
{
return _objectMapper;
}
if (ObjectMapperContext == null)
{
return LazyGetRequiredService(ref _objectMapper);
}
return LazyGetRequiredService(
typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext),
ref _objectMapper
);
}
}
private IObjectMapper _objectMapper;
protected Type ObjectMapperContext { get; set; }
protected TService LazyGetRequiredService<TService>(ref TService reference) => LazyGetRequiredService(typeof(TService), ref reference);
protected TRef LazyGetRequiredService<TRef>(Type serviceType, ref TRef reference)
{
if (reference == null)
{
reference = (TRef)ScopedServices.GetRequiredService(serviceType);
}
return reference;
}
protected TService LazyGetService<TService>(ref TService reference) => LazyGetService(typeof(TService), ref reference);
protected TRef LazyGetService<TRef>(Type serviceType, ref TRef reference)
{
if (reference == null)
{
reference = (TRef)ScopedServices.GetService(serviceType);
}
return reference;
}
protected TService LazyGetNonScopedRequiredService<TService>(ref TService reference) => LazyGetNonScopedRequiredService(typeof(TService), ref reference);
protected TRef LazyGetNonScopedRequiredService<TRef>(Type serviceType, ref TRef reference)
{
if (reference == null)
{
reference = (TRef)NonScopedServices.GetRequiredService(serviceType);
}
return reference;
}
protected TService LazyGetNonScopedService<TService>(ref TService reference) => LazyGetNonScopedService(typeof(TService), ref reference);
protected TRef LazyGetNonScopedService<TRef>(Type serviceType, ref TRef reference)
{
if (reference == null)
{
reference = (TRef)NonScopedServices.GetService(serviceType);
}
return reference;
}
[Inject]
protected IServiceProvider NonScopedServices { get; set; }
protected virtual IStringLocalizer CreateLocalizer()
{
if (LocalizationResource != null)
{
return StringLocalizerFactory.Create(LocalizationResource);
}
var localizer = StringLocalizerFactory.CreateDefaultOrNull();
if (localizer == null)
{
throw new AbpException($"Set {nameof(LocalizationResource)} or define the default localization resource type (by configuring the {nameof(AbpLocalizationOptions)}.{nameof(AbpLocalizationOptions.DefaultResourceType)}) to be able to use the {nameof(L)} object!");
}
return localizer;
}
protected virtual async Task HandleErrorAsync(Exception exception)
{
Logger.LogException(exception);
await InvokeAsync(async () =>
{
await UserExceptionInformer.InformAsync(new UserExceptionInformerContext(exception));
StateHasChanged();
});
}
}
}
After the blazer server is deployed through nginx, when requesting the auth service redirect _uri is http instead of https, and through the logs of the auth service redirect _uri is also http, this redirect_uri How does need to be configured to obtain https?
How to customize the login page if it is Blazor?Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, and please first use the search on the homepage. Provide us with the following info:
在提问之前先查看文档:https://docs.abp.io/en/commercial/latest/ 检查样本以查看基本任务:https://docs.abp.io/en/commercial/latest/samples/index 您的问题的解决方案之前可能已经有答案,请先使用首页搜索。 向我们提供以下信息:
@page "/" <NumericEdit TValue="int"></NumericEdit>
this is result