我可以从ASP.NET应用程序外的ASP.NET页面对象中呈现html吗?

Thi*_*uda 5 .net c# asp.net httprequest httpcontext

我不是在谈论使用'ApplicationHost'类托管ASP.NET.例如,如果我创建一个Console应用程序,创建一个有效的HttpContext对象并将其传递给自定义Page对象的ProcessRequest,它是否会填充HttpReponse html,就好像它在ASP.NET中运行一样?

Bif*_*iff 3

我不明白为什么不。

尝试使用 RenderControl() 方法从页面或 Web 控件获取 html。

static public string GetHTML(Control myControl)
{
        System.IO.StringWriter sw = new System.IO.StringWriter();
        HtmlTextWriter myWriter = new HtmlTextWriter(sw);
        myControl.RenderControl(myWriter);
        return sw.ToString();
}
Run Code Online (Sandbox Code Playgroud)

我用它来异步渲染 GridView。