Reputation: 5
I am using the following code to change the rendermodes programatically:
@code{
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;
private IComponentRenderMode? RenderModeForPage => HttpContext.Request.Path.StartsWithSegments("/login") ? null : InteractiveServer;
}
I have an SSR /login page where I am using cookie authentication. If I open /forgot-password page without logging in, the rendermode changes to InteractiveServer, but after that if I go back in the browser to the /login page and finally try to log in, It throws me an System.InvalidOperationException: 'Headers are read-only, response has already started.' exception because rendermode remains InteractiveServer.
I tried to solve this issue with the NavigationManager LocationChanged Event but it does not worked great, beacuse the event not triggered when the application started. Which is the best way to change the rendermode based on the current URL of my application?
Upvotes: 0
Views: 64