Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

"Invalid non-ASCII or control character in header: 0x00E7" when redirect to a URL with non-ASCII (e.g: ç) #2296

@TiagoSoczek

Description

@TiagoSoczek

Hi everyone,

When attempting to redirect to a URL containing a non-ASCII character, Kestrel throws the following exception:

System.InvalidOperationException: Invalid non-ASCII or control character in header: 0x00E7
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders.ThrowInvalidHeaderCharacter(Char ch)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders.ValidateHeaderCharacters(String headerCharacters)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders.ValidateHeaderCharacters(StringValues headerValues)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameResponseHeaders.SetValueFast(String key, StringValues value)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders.Microsoft.AspNetCore.Http.IHeaderDictionary.set_Item(String key, StringValues value)
   at Microsoft.AspNetCore.Http.Internal.DefaultHttpResponse.Redirect(String location, Boolean permanent)
   at Microsoft.AspNetCore.Mvc.Internal.RedirectResultExecutor.Execute(ActionContext context, RedirectResult result)
   at Microsoft.AspNetCore.Mvc.RedirectResult.ExecuteResult(ActionContext context)
   at Microsoft.AspNetCore.Mvc.ActionResult.ExecuteResultAsync(ActionContext context)

Sample code:

    [Route("[controller]")]
    public class HomeController : Controller
    {
        [HttpGet]
        public IActionResult Goto() => Redirect("http://example.com/façade.pdf");
    }

The same Redirect works correctly on ASP.NET MVC 5.2.3.

I'm aware the HTTP don't allow non-ASCII character in the URL, but, this can be considered an bug? If no, what is the best recommendation here? Encode the URL before redirect?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions