Render a page inside of an HttpModule?

强颜欢笑 提交于 2019-12-01 09:36:53

问题


Anyone got an idea of how to render an aspx page inside of an HttpModule and stream it back to the browser?


回答1:


You can do something like this:

Type page_type = BuildManager.GetCompiledType ("~/page.aspx");
Page page = (Page) Activator.CreateInstance (page_type);
page.ProcessRequest (Context);



回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/1732184/render-a-page-inside-of-an-httpmodule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!