In ASP.net, page is actually a httphandler, which processes the request, and then returns a whole bunch of HTML. So is it possible to instantiate a page class and get the results of its processing? A simple reasoning can explain that this is not possible. Because if we instantiate page, so the new page (), this is a standard. NET code, the compiler is not aware of the relevant page.aspx content. So you need Pagepaser help, and Pagepaser is also a key step in asp.net internal compilation process. Here's how to use it:
protected void Page_Load (object sender, EventArgs e)
{
Response.Write (Httputility.htmlencode (Dumphtmlfrom ("~/default.aspx"));
}
Virtualpath:allow queries
String Dumphtmlfrom (String virtualpath)
{
StringWriter writer = new StringWriter ();
var path = Request.Url.Scheme + "://" + Request.Url.Authority + virtualpathutility.toabsolute (virtualpath);
var parts = virtualpath.split ('? ');
string query = String. Empty;
if (parts. Length > 1)
query = Parts[1];
VirtualPath = Parts[0];
HttpContext context = new HttpContext (New HttpRequest (virtualpath, path, query), new HttpResponse (writer));
var handler = pageparser.getcompiledpageinstance (VirtualPath, MapPath (virtualpath), context);
Handler. ProcessRequest (context);
return writer. ToString ();
}
One of the key steps Pageparser.getcompiledpageinstance instantiate a HttpHandler and return all the HTML.