All*_*est 3 c# character-encoding non-ascii-characters asp.net-core
如果我将此Startup放在ASP.NET Core应用程序中,文本将被加扰(Ã...Ã"Ã-).如果我在中间件中这样做,也会发生同样的事情.传递Encoding.UTF8
到WriteAsync
于事无补.
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.Run(async context => { await context.Response.WriteAsync("ÅÄÖ"); });
}
}
Run Code Online (Sandbox Code Playgroud)
怎么了?我该怎么做才能解决它?
您需要提供正确的Content-Type
标题.没有它,浏览器就会猜测内容响应代表什么,以及编码.当然,如果猜测不正确就没有错,就像你的情况一样.
app.Run(async context => {
// text in UTF-8
context.Response.ContentType = "text/plain; charset=utf-8";
await context.Response.WriteAsync("ÅÄÖ");
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
630 次 |
最近记录: |