Asp.net IIS7错误:目标多字节代码页中不存在Unicode字符的映射
当url包含中文字符时,我遇到问题。并非每次都会发生,但当发生时,我在事件日志中发现以下错误:Asp.net IIS7错误:目标多字节代码页中不存在Unicode字符的映射,asp.net,iis-7,unicode,Asp.net,Iis 7,Unicode,当url包含中文字符时,我遇到问题。并非每次都会发生,但当发生时,我在事件日志中发现以下错误: EventMessage No mapping for the Unicode character exists in the target multi-byte code page. (Exception from HRESULT: 0x80070459) EventStackTrace System.ArgumentOutOfRangeException: No mapping
EventMessage
No mapping for the Unicode character exists in the target multi-byte code page. (Exception from HRESULT: 0x80070459)
EventStackTrace
System.ArgumentOutOfRangeException: No mapping for the Unicode character exists in the target multi-byte code page. (Exception from HRESULT: 0x80070459)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name)
at System.Web.Hosting.IIS7WorkerRequest.GetServerVariable(String name)
at System.Web.Hosting.IIS7WorkerRequest.ReadRequestHeaders()
at System.Web.Hosting.IIS7WorkerRequest.GetKnownRequestHeader(Int32 index)
at System.Web.HttpRequest.FillInHeadersCollection()
at System.Web.HttpRequest.get_Headers()
异常似乎是在本机方法中引发的。当Cookie或其他头包含unicode字符时,似乎会发生这种情况。这可能会对问题和解决方案有所帮助。当Cookie或其他头包含unicode字符时,似乎会发生这种情况。这可能会对问题和解决方案有所帮助。我通过以
Base64String
的形式发送数据来解决它,在我的情况下,它是一个对象:
byte[] bytes = Encoding.UTF8.GetBytes(Json.Convert(myObject))
client.DefaultRequestHeaders.Add("data" , Convert.ToBase64String(bytes));
我通过将数据作为
Base64String
发送解决了这个问题,在我的例子中,它是一个对象:
byte[] bytes = Encoding.UTF8.GetBytes(Json.Convert(myObject))
client.DefaultRequestHeaders.Add("data" , Convert.ToBase64String(bytes));
+1.在cookie中包含非ASCII字符在不同的浏览器和服务器中是非常不可靠的。始终编码为7位安全格式(例如URL编码cookie值)。谢谢,链接可能来自我们这边。我们总是对url进行编码,因为使用unicode字符,在使用II6+1时不会发生这种情况。在cookie中包含非ASCII字符在不同的浏览器和服务器中是非常不可靠的。始终编码为7位安全格式(例如URL编码cookie值)。谢谢,链接可能来自我们这边。我们总是对url进行编码,因为使用unicode字符时,不会发生这种情况