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