Skip to content

InvalidOperationException occurs on onsubmit event when using NavigateTo method with non-ASCII characters on Blazor SSR render mode. #52438

Closed
@runceel

Description

@runceel

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

InvalidOperationException occurs on onsubmit event when using NavigateTo method with non-ASCII characters on Blazor SSR render mode. Only ASCII case works fine.

// OK
NavigationManager.NavigateTo("navtarget?text=HelloWorld");

// Error
NavigationManager.NavigateTo("navtarget?text=😀");

The error page:
image

The stack trace:

InvalidOperationException: Invalid non-ASCII or control character in header: 0xD83D
Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.ThrowInvalidHeaderCharacter(char ch)
Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.ValidateHeaderValueCharacters(string headerCharacters, bool requireAscii)
Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.ValidateHeaderValueCharacters(string headerName, StringValues headerValues, Func<string, Encoding> encodingSelector)
Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseHeaders.Microsoft.AspNetCore.Http.IHeaderDictionary.set_Location(StringValues value)
Microsoft.AspNetCore.Components.Endpoints.EndpointHtmlRenderer.HandleNavigationException(HttpContext httpContext, NavigationException navigationException)
Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.RenderComponentCore(HttpContext context)
Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.RenderComponentCore(HttpContext context)
Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext+<>c+<<InvokeAsync>b__10_0>d.MoveNext()
Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryMiddleware.InvokeAwaited(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Expected Behavior

Navigating works without error.

Steps To Reproduce

Scratch

  1. Create a Blazor Web App project.
  • Authentication type: None
  • Interactive render mode: None
  • Interactivity location: Per page/component
  • Uncheck Include sample pages
    image
  1. Edit Components/Pages/Home.razor like below:
@page "/"
@inject NavigationManager NavigationManager

<PageTitle>Home</PageTitle>

<form method="post" @formname="form1" @onsubmit="Navigate">
    <AntiforgeryToken />
    <input type="submit" />
</form>

@code {
    private void Navigate() => 
        NavigationManager.NavigateTo("somepage?text=😀");
}
  1. Launch the project.
  2. Click the submit button.

Use a repro project

I created a sample project for repro.
https://github.com/runceel/NoAsciiError

  1. Clone the repository.
  2. Open NoAsciiError.sln
  3. Launch the project
  4. Click NavigationManager.NavigateTo("navtarget?text=😀") button.

Exceptions (if any)

No response

.NET Version

8.0.100

Anything else?

I faced the error when implement a search page like Bing and Google.
Those pages have a textbox and a submit button. And then search result page has search key words in query parameters.
If search key worlds are non ASCII characters such as Emoji and Japanese and other languages, the error occurs.
I guess it is a serious blocker to use Blazor SSR mode.

Metadata

Metadata

Assignees

Labels

area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions