这就是我通常执行aspx Web表单并从输出中获取字符串的方式:
public static string GetAspPageOutput(string page)
{
string html;
using (var sw = new StringWriter())
{
HttpContext.Current.Server.Execute(page, sw);
html = sw.ToString();
}
return html;
}
我如何获得字节数组呢?
答案 0 :(得分:0)
建议来自这篇文章https://stackoverflow.com/a/1745456/3646986。使用StreamWriter而不是StringWriter
MemoryStream ms = new MemoryStream();
StreamWriter writer = new StreamWriter(ms);
context.Server.Execute(virtualpath, writer);
var bytes = ms.toArray()
return bytes