ASP.NET:Server.Execute()中的BOM [英] ASP.NET: BOM in Server.Execute()
本文介绍了ASP.NET:Server.Execute()中的BOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用它来写响应流:
I'm using this to write to the Response stream:
using (var writer = new StringWriter())
{
context.Server.Execute(virtualpath, writer);
string s = writer.ToString().Replace(...);
context.Response.Write(s);
}
但是我在响应中得到一个字节顺序标记.我会搞乱编码吗?如何不退回BOM?
But I'm getting a byte order mark in the response. Am I screwing up the encoding? How do I NOT return the BOM?
对不起鲁本斯,我的第一个例子是不正确的.
SOrry Rubens, my first example was incorrect.
推荐答案
尝试一下:
context.Server.Execute(virtualpath, context.Response.Output);
编辑:因此,请尝试执行此操作以强制进行编码:
EDIT: So, try this to force your encoding:
MemoryStream ms = new MemoryStream();
StreamWriter writer = new StreamWriter(ms);
context.Server.Execute(virtualpath, writer);
context.Response.Write(Encoding.UTF8.GetString(ms.ToArray()).Replace(...));
这篇关于ASP.NET:Server.Execute()中的BOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文