69 lines
1.6 KiB
C#
69 lines
1.6 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
|
|
namespace MP.IOC.Components.Compo
|
|
{
|
|
public partial class CmpTop : IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
GC.Collect();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected AuthenticationStateProvider AuthenticationStateProvider { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await forceReload();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private string userName = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private string PageIcon { get; set; }
|
|
|
|
private string PageName { get; set; }
|
|
|
|
[CascadingParameter(Name = "ShowSearch")]
|
|
private bool ShowSearch { get; set; }
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task forceReload()
|
|
{
|
|
userName = "N.A.";
|
|
await Task.Delay(1); var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
|
var user = authState.User;
|
|
if (user.Identity != null && user.Identity.IsAuthenticated)
|
|
{
|
|
userName = $"{user.Identity.Name}";
|
|
}
|
|
else
|
|
{
|
|
userName = "N.A.";
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |