Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Blazor SSR] Issue with NavigationManager.NavigateTo and Already Percent-Encoded URLs #53708

Closed
1 task done
JeepNL opened this issue Jan 30, 2024 · 4 comments
Closed
1 task done
Labels
area-blazor Includes: Blazor, Razor Components Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue

Comments

@JeepNL
Copy link
Contributor

JeepNL commented Jan 30, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Note: maybe this issue is already fixed with #53138, #53470 but I can't tell. If it is fixed, you can of course close this issue directly.

In Blazor applications, specifically when using Server Side Rendering (SSR) with .NET 8, I've encountered an issue where NavigationManager.NavigateTo does not correctly handle navigation when provided with already percent-encoded URLs.

Expected Behavior

NavigationManager.NavigateTo should correctly handle already percent-encoded URLs, allowing for successful navigation without errors.

Steps To Reproduce

Create a Blazor Server Side Rendering application using .NET 8.
Attempt to use NavigationManager.NavigateTo to navigate to a URL that contains percent-encoded characters (e.g., https://www.nvj.nl/nieuws/offici%C3%ABle-waarschuwing-zonder-wederhoor-mag).
Observe that the navigation does not work as expected, and an error is thrown.

Exceptions (if any)

info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
      Executed endpoint '/ext/{text} (/ext/{text})'
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
      System.InvalidOperationException: Invalid non-ASCII or control character in header: 0x00EB
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.ThrowInvalidHeaderCharacter(Char ch)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.ValidateHeaderValueCharacters(String headerCharacters, Boolean requireAscii)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.ValidateHeaderValueCharacters(String headerName, StringValues headerValues, Func`2 encodingSelector)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseHeaders.Microsoft.AspNetCore.Http.IHeaderDictionary.set_Location(StringValues value)
         at Microsoft.AspNetCore.Components.Endpoints.EndpointHtmlRenderer.HandleNavigationException(HttpContext httpContext, NavigationException navigationException)
         at Microsoft.AspNetCore.Components.Endpoints.EndpointHtmlRenderer.RenderEndpointComponent(HttpContext httpContext, Type rootComponentType, ParameterView parameters, Boolean waitForQuiescence)
         at Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.RenderComponentCore(HttpContext context)
         at Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.RenderComponentCore(HttpContext context)
         at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c.<<InvokeAsync>b__10_0>d.MoveNext()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)
         at Microsoft.AspNetCore.HttpLogging.W3CLoggingMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatcher|10_0(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task`1 matcherTask)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

.NET Version

8.0.200-preview.23624.5

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Jan 30, 2024
@javiercn
Copy link
Member

@JeepNL thanks for contacting us.

This is likely unrelated. The issues mentioned are inbound, not outbound. In this case the issue seems to be happening when you try to navigate, as something invalid ends up in the header.

@javiercn javiercn added the Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue label Jan 30, 2024
@ghost
Copy link

ghost commented Jan 30, 2024

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimal repro project that illustrates the problem without unnecessary code. Please share with us in a public GitHub repo because we cannot open ZIP attachments, and don't include any confidential content.

@ghost ghost added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Jan 30, 2024
@MackinnonBuck
Copy link
Member

Hi @JeepNL, this is getting fixed by #53623, which will be included in one of the upcoming .NET 8 servicing release. I'm going to close out this issue, but we can reopen it if we get feedback that the issue persists. Thanks!

@JeepNL
Copy link
Contributor Author

JeepNL commented Jan 30, 2024

@javiercn @MackinnonBuck Thank you both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue
Projects
None yet
Development

No branches or pull requests

3 participants