苏飞论坛

标题: 彻底解决“在多字节的目标代码页中,没有此Unicode字符可以映射到的字符” [打印本页]

作者: 站长苏飞    时间: 2016-8-18 10:39
标题: 彻底解决“在多字节的目标代码页中,没有此Unicode字符可以映射到的字符”
[C#] 纯文本查看 复制代码
[ArgumentOutOfRangeException: 在多字节的目标代码页中,没有此 Unicode 字符可以映射到的字符。 (异常来自 HRESULT:0x80070459)]
   System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) +0
   System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) +13563503
   System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name) +50
   System.Web.Hosting.IIS7WorkerRequest.ReadRequestHeaders() +144
   System.Web.Hosting.IIS7WorkerRequest.GetKnownRequestHeader(Int32 index) +109
   System.Web.HttpWorkerRequest.HasEntityBody() +27
   System.Web.HttpRequest.GetEncodingFromHeaders() +126
   System.Web.HttpRequest.get_ContentEncoding() +162
   System.Web.HttpRequest.get_QueryStringEncoding() +10
   System.Web.HttpRequest.get_QueryStringText() +209
   System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +87
   System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +55


我相信有不少同学都看到过类似的问题
上面那句“在多字节的目标代码页中,没有此 Unicode 字符可以映射到的字符”对应的英文是
[C#] 纯文本查看 复制代码
No mapping for the Unicode character exists in the target multi-byte code page.

博客园的dudu是这样解决的
[C#] 纯文本查看 复制代码
<rule name="block_invalid_tag_url" stopProcessing="true">
    <match url="^[^/]+/tag/.*?\?.*$" />
    <action type="CustomResponse" statusCode="404" statusReason="The request URL is invalid"
        statusDescription="The request URL is invalid" />
</rule>

个人感觉这种只是徒有其表,并没有真的解决问题,
还是要详细分析是一下具体是什么问题造成的,
这种情况多半出在IE里面,
大部分就应该是Cookie引起的,就是Cookie的值里面包含的特殊字符或者中文
那我们在写Cookie时只要转一个码就不会有这样的兼容性问题了。
代码如下
[C#] 纯文本查看 复制代码
HttpCookie cookie = new HttpCookie("uname", HttpUtility.UrlEncode(uname));
                    cookie.Expires = DateTime.Now.AddMonths(4);
                    Response.AppendCookie(cookie);


作者: 站长苏飞    时间: 2016-8-18 10:39
这种情况通常只会在IIS7中出现,IIS6暂时没有发现有过类似情况
作者: hqx    时间: 2019-8-28 10:03
站长苏飞 发表于 2016-8-18 10:39
这种情况通常只会在IIS7中出现,IIS6暂时没有发现有过类似情况

怎么转码呢?





欢迎光临 苏飞论坛 (http://www.sufeinet.com/) Powered by Discuz! X3.4