ASP.NET 响应 - UTF-16 编码文件但浏览器中未显示任何内容

ASP.NET Response - UTF-16 encoded file but nothing shown in the browser

我正在尝试从 ASP.NET 应用发送 UTF-16BE 文本文件作为 HTTP 响应。

Response.ContentType = "text/plain";
Response.ContentEncoding = System.Text.UnicodeEncoding.BigEndianUnicode;
Response.WriteFile(filename);

但结果没有显示,Fiddler 也没有显示任何编码

是我的问题还是网络浏览器不喜欢 utf-16 文本?

不,您的网络浏览器不是问题。

此代码:

context.Response.ContentType = "text/html";
context.Response.ContentEncoding = UnicodeEncoding.BigEndianUnicode;
context.Response.Write("Hello World");

产生预期的内容编码:

但是一旦您使用 context.Response.WriteFile,内容编码就会被删除。不确定这是否是一项功能。我假设另一端的软件必须根据返回的输出来确定内容编码。