Closed
Description
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 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
- Create a Blazor Web App project.
- Authentication type: None
- Interactive render mode: None
- Interactivity location: Per page/component
- Uncheck Include sample pages
- 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=😀");
}
- Launch the project.
- Click the submit button.
Use a repro project
I created a sample project for repro.
https://github.com/runceel/NoAsciiError
- Clone the repository.
- Open NoAsciiError.sln
- Launch the project
- 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
Type
Projects
Status
Done