.net core下载文件中文报错:Invalid non-ASCII or control character in header: 电脑版发表于:2018/6/9 11:12 .net core下载附件遇到中文下载会报错:InvalidOperationException: Invalid non-ASCII or control character in header: 0x7528。 使用url编码一下就可以解决了 ``` WebUtility.UrlEncode("用户信息表.xls") ``` 整体代码如下: ``` //把内存流做为文件下载中转 MemoryStream memoryStream = new MemoryStream(); workbook.Write(memoryStream); //Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); Response.ContentType = "application/octet-stream;charset=UTF-8"; ; string newName = Guid.NewGuid().ToString().Replace("-", ""); Response.Headers.Add("Content-Disposition", "attachment;filename=" + WebUtility.UrlEncode("用户信息表.xls")); //Response.Headers.Add("Content-Disposition", "attachment;filename=用户信息表.xls"); Response.BodyWriter.WriteAsync(memoryStream.ToArray()); Response.BodyWriter.FlushAsync(); ```