在Ria项目中经常使用ashx输出xml,直接在Chrome/FF/IE中显示正常,但是Flash读取的是都是中文乱码。

ashx默认的内容类型是"text/plain",改为"text/xml"后,Flash获取还是中文乱码;Response.Write加上<?xml version="1.0" encoding="utf-8"?>表头还是不行;使用System.Text下的特定转码还是不行;改为gb2312编码还是不行.....

 

多次尝试后解决方法如下:

        context.Response.ContentType = "text/xml";
        
        //获取当前的系统的编码  flash中就不会出错了 都是如果含有cdata的节点ie中会出错,flash中正常(-_-)
        context.Response.ContentEncoding = System.Text.Encoding.Default;    
        context.Response.Cache.SetCacheability(HttpCacheability.Public);
        context.Response.BufferOutput = false;

web.config中加入:

 <system.web>
        <globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
</system.web>