0

这就是我通常执行 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;
}

我如何获得一个字节数组?

4

1 回答 1

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
于 2017-07-07T06:17:22.853 回答