现在的位置: 首页 > 综合 > 正文

解决:iis7,在多字节的目标代码页中,没有此 Unicode 字符可以映射到的字符。 (异常来自 HRESULT:0×80070459)

2012年09月28日 ⁄ 综合 ⁄ 共 449字 ⁄ 字号 评论关闭

当我们asp.net程序迁移到iis7时,如果页面cookie中存在未编码的汉字时,iis内核就会报错,

错误信息如下:

在多字节的目标代码页中,没有此 Unicode 字符可以映射到的字符。 (异常来自 HRESULT:0x80070459)

对应的英文错误信息如下:

No mapping for the Unicode character exists in the target multi-byte code page

 

经过单元测试,确实如此,iis6下还未测试,不知是否会发生此情况

 

解决方案:存储cookie值经过url编码即可,上代码

HttpCookie cookie = new HttpCookie("username", HttpUtility.UrlEncode(userName));
                    cookie.Expires = DateTime.Now.AddMonths(1);
                    Response.AppendCookie(cookie);

 

抱歉!评论已关闭.