Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor - AuthorizeRouteView causing ERR_CERT_DATE_INVALID error

$
0
0

I am attempting to use a cascading authentication state in my Blazor application. I have utilized this custom authentication in previous Blazor applications and haven't yet come across this issue. Prior to adding my cascading authorization state, the application worked as expected with no problems. But I noticed that when I updated my Routes.razor page, I started to get the following error:

failed: Error in connection establishment: net::ERR_CERT_DATE_INVALID(anonymous) @ aspnetcore-browser-refresh.js:350getWebSocket @ aspnetcore-browser-refresh.js:347(anonymous) @ aspnetcore-browser-refresh.js:16Understand this errorblazor.web.js:1 [2025-09-30T17:19:44.428Z] Error: System.InvalidOperationException: The ConnectionString property has not been initialized.

The below code is my current Routes.razor page:

<CascadingAuthenticationState><Router AppAssembly="typeof(Program).Assembly"><Found Context="routeData"><AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)"><NotAuthorized><LoginRedirect/></NotAuthorized></AuthorizeRouteView><FocusOnNavigate RouteData="routeData" Selector="h1" /></Found><NotFound><PageTitle>Not found</PageTitle><LayoutView Layout="@typeof(Layout.MainLayout)"><p role="alert">Sorry, there's nothing at this address.</p></LayoutView></NotFound></Router></CascadingAuthenticationState>@rendermode InteractiveServer

When I change my Routes.razor file to the following, it works without issue, which made me think it was coming down to my AuthorizeRouteView:

<CascadingAuthenticationState><Router AppAssembly="typeof(Program).Assembly"><Found Context="routeData"><RouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)"></RouteView><FocusOnNavigate RouteData="routeData" Selector="h1" /></Found><NotFound><PageTitle>Not found</PageTitle><LayoutView Layout="@typeof(Layout.MainLayout)"><p role="alert">Sorry, there's nothing at this address.</p></LayoutView></NotFound></Router></CascadingAuthenticationState>@rendermode InteractiveServer

For reference, my CustomAuthentication.cs works as follows:

    using Microsoft.AspNetCore.Components.Authorization;    using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;    using System.Security.Claims;    namespace Test.Authentication    {        public class CustomAuthentication : AuthenticationStateProvider        {            private readonly ProtectedSessionStorage _sessionStorage;            private ClaimsPrincipal _anonymous = new ClaimsPrincipal(new ClaimsIdentity());            public CustomAuthentication(ProtectedSessionStorage sessionStorage)            {                _sessionStorage = sessionStorage;            }            public override async Task<AuthenticationState> GetAuthenticationStateAsync()            {                try                {                    var userSessionStorageResult = await     _sessionStorage.GetAsync<UserSession>("UserSession");                        var userSession = userSessionStorageResult.Success ? userSessionStorageResult.Value : null;                    if (userSession == null)                    {                        return await Task.FromResult(new AuthenticationState(_anonymous));                    }                    var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>                {                    new Claim(ClaimTypes.Name, userSession.UserName),                    new Claim(ClaimTypes.Role, userSession.Role),                }, "CustomAuth"));                    return await Task.FromResult(new AuthenticationState(claimsPrincipal));                }                catch                {                    return await Task.FromResult(new AuthenticationState(_anonymous));                }            }            public async Task UpdateAuthenticationState(UserSession userSession)            {                ClaimsPrincipal claimsPrincipal;                if (userSession != null)                {                    await _sessionStorage.SetAsync("UserSession", userSession);                    claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>                    {                        new Claim(ClaimTypes.Name, userSession.UserName),                        new Claim(ClaimTypes.Role, userSession.Role)                    }));                }                else                {                    await _sessionStorage.DeleteAsync("UserSession");                    claimsPrincipal = _anonymous;                }                NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(claimsPrincipal)));            }        }    }

I also checked with my IT department, and was told that the local testing environment that I'm in does not have encryption setup. So my DefaultConnection string contains "Encrypt=False".

Any help would be appreciated as to how to solve this error.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>