50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using System.Net;
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
namespace BlazorApp.Pages.User
|
|
{
|
|
public class UserListBase : ComponentBase
|
|
{
|
|
|
|
|
|
|
|
[CascadingParameter]
|
|
public Task<AuthenticationState> authenticationStateTask { get; set; }
|
|
|
|
[Inject]
|
|
public NavigationManager NavigationManager { get; set; }
|
|
|
|
|
|
protected async override Task OnInitializedAsync()
|
|
{
|
|
|
|
var authenticationState = await authenticationStateTask;
|
|
//var UserResult = await _userManager.IsInRoleAsync(user, "Administrators");
|
|
//if (!authenticationState.User.IsInRole("Administrators"))
|
|
//{
|
|
// NavigationManager.NavigateTo("/");
|
|
// return;
|
|
|
|
//}
|
|
//if (!authenticationState.User.HasClaim(c => c.Type=="Administrators"))
|
|
//{
|
|
// NavigationManager.NavigateTo("/");
|
|
// return;
|
|
//}
|
|
if (!authenticationState.User.Identity.IsAuthenticated)
|
|
{
|
|
string returnUrl = WebUtility.UrlEncode($"/User/UserList/");
|
|
NavigationManager.NavigateTo(WebUtility.UrlEncode("/identity/Account/Login?returnUrl=/User/UserList"));
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|