2017-02-21 30 views
0

這就是我正常執行一個aspx web窗體,並從輸出的字符串:HttpServerUtility.Execute可以獲取二進制數據嗎?

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

頁面是否寫入二進制響應?還是你想要將這個HTML轉換爲一個字節數組? – mason

+0

是的,該頁面正在使用'HttpResponse.BinaryWrite'。 –

回答

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 
相關問題