Invalid non-ASCII or control character in header on redirect
General speaking, it is caused by the Redirect(returnUrl)
.
This method will return a RedirectResult(url)
and finally set the Response.Headers["Location"]
as below :
Response.Headers[HeaderNames.Location] = returnUrl;
But the Headers
of HTTP doesn't accept non-ASCII characters.
There're already some issues(#2678 , #4919) suggesting to encode the URL by default.
But there's no such a out-of-box function yet.
A quick fix to your issue:
var host= "http://localhost:60695";
var path = "/ShowProduct/2/شال-آبی";
path=String.Join(
"/",
path.Split("/").Select(s => System.Net.WebUtility.UrlEncode(s))
);
return Redirect(host+path);
Another simpler option (works for me):
var uri = new Uri(urlStr);
return Redirect(uri.AbsoluteUri);