views:

64

answers:

2

I'm not talking about hosting ASP.NET with the 'ApplicationHost' class. For example, if I create a Console application, create a valid HttpContext object and pass it to the ProcessRequest of a custom Page object, will it fill the HttpReponse html like if it was running inside ASP.NET?

A: 

If you're talking custom ASP.NET controls, then you can programmatically create them and get them to render to a string easily enough. If that's something you're interested in doing, then I've done it in the past and can dig the code out for you.

Antony Scott
I'm talking about any kind of class that implements an IHttpHandler.
Thiado de Arruda
+1  A: 

I don't see why not.

Try the RenderControl() method to get the html from a page or Web control.

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();
}

I use this to render GridViews asynchronously.

Biff MaGriff
I was concerned that rendering the html would have dependencies on the Asp.Net runtime on the current appdomain
Thiado de Arruda