The page with user login authentication is not displayed even when logged in

61 views Asked by At

I have a problem in .Net MAUI Blazor like this. That is when I go to a page asking for authenticate(notice-list) it redirects me to login form but after logging in and return to that page, the login interface will appear again. But when I go to a page that doesn't exist (Sorry, there's nothing at this address), then return to notice-list it Displays the notice-list page interface. In short, when I logged in, it confirmed that there was a user and the notice-list page it confirmed that the user was authenticated, but notice-list interface doesn't show, only when I go to a page that doesn't exist and come back it display interface. Does anyone have this problem before?

The login code

private async Task Login()

{

if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
{
    errorMessage = "";
    return;
}
var Token = SecurityManager.GenerateToken("nge", "p@ssw0rd", null, null, DateTime.Now.Ticks);

var uri = baseURI + "/Users/Login?UserName=" + userName + "&Password=" + password + "&Token=" + Token;
try
{
    using (HttpClient httpClient = new HttpClient())
    {
        var response = await httpClient.GetStringAsync(uri);

        if (string.IsNullOrEmpty(response) || response == "null")
        {
            errorMessage = "";
        }
        else
        {
            var cas = new CustomAuthenticationStateProvider();
            await  cas.Login(response);

            navigationManager.NavigateTo("/device-list");
        }
    }
}
catch (Exception ex)
{
    errorMessage = " " + ex.Message;
}

}

Authorize use in notice-list

@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
0

There are 0 answers