Anyone got an idea of how to render an aspx page inside of an HttpModule and stream it back to the browser?
+2
A:
You can do something like this:
Type page_type = BuildManager.GetCompiledType ("~/page.aspx");
Page page = (Page) Activator.CreateInstance (page_type);
page.ProcessRequest (Context);
Gonzalo
2009-11-13 22:07:43
Perfect! Thanks.
David Lively
2009-11-14 06:51:21
+1
A:
public void ProcessRequest(HttpContext context)
{
using (var writer = new StringWriter())
{
context.Server.Execute("default.aspx", writer);
context.Response.ContentType = "text/html";
context.Response.Write(writer.GetStringBuilder().ToString());
}
}
Darin Dimitrov
2009-11-13 22:08:20
+1 This does, in fact, work, but I'd rather avoid server.execute().
David Lively
2009-11-13 22:16:38
A:
The best way is probably to use URL rewriting to redirect the standard Handler processing step to the page you want to render. Something like:
context.RewritePath("yourpage.aspx", false);
You could run that from the BeginRequest event handler.
RickNZ
2009-11-15 15:56:02