获取asp.net解析页面完毕后后的html代码
public string GetHtmlData(string virtualPath)
{
StringWriter writer = new StringWriter();
string path = context.Request.Url.Scheme + "://" + context.Request.Url.Authority + VirtualPathUtility.ToAbsolute(virtualPath);
string[] parts = virtualPath.Split('?');
string query = string.Empty; if (parts.Length > 1)
query = parts[1]; virtualPath = parts[0];
HttpContext context1 = new HttpContext(new HttpRequest(virtualPath, path, query), new HttpResponse(writer));
IHttpHandler handler = System.Web.UI.PageParser.GetCompiledPageInstance(virtualPath, context.Server.MapPath(virtualPath), context1);
handler.ProcessRequest(context1); return writer.ToString();
}
其中,PageParser.GetCompiledPageInstance是最关键的。