Azure WebApp中的编码问题

时间:2020-10-06 14:03:24

标签: azure character-encoding azure-web-app-service

我正尝试从我的网页下载Excel文件。在当地环境中,一切正常。但是在Azure中,文件名的编码搞砸了。我已经在web.config中设置了全球化标签,如下所示:

<globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8"/>

以下是响应的构建方式:

string name = v_NomeArquivo + ".xlsx";
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = true;
Response.ContentType = "application/ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=" + name);
Response.BinaryWrite(v_ExcelPackage.GetAsByteArray());
Response.End();

Azure上的标题:

cache-control: private
content-disposition: attachment; filename=Relatório Contrato Limpeza e Higinenização - 2020-10-06_10-55-26.xlsx
content-type: application/ms-excel
date: Tue, 06 Oct 2020 13:55:26 GMT
server: Microsoft-IIS/10.0
status: 200
x-aspnet-version: 4.0.30319
x-powered-by: ASP.NET

在本地:

Cache-Control: private
content-disposition: attachment; filename=Relatório Contrato Limpeza e Higinenização - 2020-10-06_10-58-59.xlsx
Content-Type: application/ms-excel
Date: Tue, 06 Oct 2020 13:58:59 GMT
Server: Microsoft-IIS/10.0
Transfer-Encoding: chunked
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET

唯一的区别是文件名被弄乱了,可能是传输编码吗?

1 个答案:

答案 0 :(得分:1)

您需要使用System.Web.HttpUtility.UrlEncode方法。

例如:

string name = System.Web.HttpUtility.UrlEncode(v_NomeArquivo + ".xlsx", System.Text.Encoding.UTF8);
相关问题