Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Internet explorer 向HttpContext.Current.Response.AddHeader()添加特殊字符_Internet Explorer_C# 4.0_Httpresponse - Fatal编程技术网

Internet explorer 向HttpContext.Current.Response.AddHeader()添加特殊字符

Internet explorer 向HttpContext.Current.Response.AddHeader()添加特殊字符,internet-explorer,c#-4.0,httpresponse,Internet Explorer,C# 4.0,Httpresponse,我想生成带有特殊字符的PDF文件 我的代码如下: MemoryStream memoryStream = // get memory stream relevant to pdf file HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.U

我想生成带有特殊字符的PDF文件

我的代码如下:

 MemoryStream memoryStream = // get memory stream relevant to pdf file
 HttpContext.Current.Response.Clear();
 HttpContext.Current.Response.Buffer = true;
 HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF32;               
 HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}.pdf", downloadLink));
 HttpContext.Current.Response.ContentType = @"application/pdf";
 HttpContext.Current.Response.BinaryWrite(memoryStream.ToArray());
这适用于downloadLink的普通字符。但对于特殊字符,如ABC_50_Rom–nă,则下载文件包含名为ABC_50_RomÃ、nă的未识别字符

我尝试使用System.Text.Encoding.UTF32;和Encoding.GetEncodingWindows-1252用于ContentEncoding。但无法解决问题

编辑:
此问题仅在internet explorer中出现

我通过在调用Response.AppendHeader之前将文件名转换为UTF8来解决此问题

        if ((HttpContext.Current.Request.Browser.Type.ToUpper(CultureInfo.InvariantCulture).StartsWith("IE")) || (HttpContext.Current.Request.Browser.Type.ToUpper(CultureInfo.InvariantCulture).StartsWith("INTERNETEXPLORER")))
            downloadLink = HttpUtility.UrlEncode(downloadLink, UTF8Encoding.UTF8).Replace("+", " ");

中找到的好文章不仅仅是IE-per,标题中只允许使用ASCII字符。每个浏览器都可以使用自己的变通方法来恢复预期的数据。尝试在发送文件名之前对其进行URL编码。这在-。答案提出了实现服务器特定编码的各种方法,因为BCL是。。。内部的