【发布时间】:2011-08-25 19:51:21
【问题描述】:
有人知道如何在 HttpModule 中呈现一个 aspx 页面并将其流式传输回浏览器吗?
【问题讨论】:
标签: asp.net httphandler httpmodule
有人知道如何在 HttpModule 中呈现一个 aspx 页面并将其流式传输回浏览器吗?
【问题讨论】:
标签: asp.net httphandler httpmodule
你可以这样做:
Type page_type = BuildManager.GetCompiledType ("~/page.aspx");
Page page = (Page) Activator.CreateInstance (page_type);
page.ProcessRequest (Context);
【讨论】:
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());
}
}
【讨论】:
最好的方法可能是使用 URL 重写将标准 Handler 处理步骤重定向到您要呈现的页面。比如:
context.RewritePath("yourpage.aspx", false);
您可以从 BeginRequest 事件处理程序中运行它。
【讨论】: