嗨,我有这个控制器的动作:
[HttpGet("vn/{word}", Name = "GetTranslationForVnWord")]
public async Task<IActionResult> GetTranslationForVnWord(string word)
{
return Ok(word);
}
发送包含越南语字符(utf-16)的获取请求时出现此异常:
请求:http://localhost:53976/api/gervntranslations/vn/kéo
例外:
System.Text.DecoderFallbackException:无法将索引 26 处的字节 [E9] 从指定代码页转换为 Unicode。在 System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index) 在 System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index) 在 System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes) 在 System.Text.UTF8Encoding.GetCharCount(Byte* bytes, Int32 count, DecoderNLS baseDecoder) 在 System.String.CreateStringFromEncoding(Byte* bytes, Int32 byteLength, Encoding encoding) 在 System.Text.UTF8Encoding.GetString(Byte[]字节,Int32 索引,Int32 计数)在 Microsoft.AspNetCore.HttpSys.Internal.RequestUriBuilder.DecodeAndUnescapePath(Byte[] rawUrlBytes) 在 Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext。
我如何配置 asp.net core 以避免这个问题?