【问题标题】:Render a page inside of an HttpModule?在 HttpModule 中渲染页面?
【发布时间】:2011-08-25 19:51:21
【问题描述】:

有人知道如何在 HttpModule 中呈现一个 aspx 页面并将其流式传输回浏览器吗?

【问题讨论】:

    标签: asp.net httphandler httpmodule


    【解决方案1】:

    你可以这样做:

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

      【讨论】:

      • +1 这确实有效,但我宁愿避免使用 server.execute()。
      【解决方案3】:

      最好的方法可能是使用 URL 重写将标准 Handler 处理步骤重定向到您要呈现的页面。比如:

      context.RewritePath("yourpage.aspx", false);
      

      您可以从 BeginRequest 事件处理程序中运行它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-01-30
        • 2015-07-21
        • 2023-04-03
        • 1970-01-01
        • 2011-03-19
        • 2019-12-20
        • 1970-01-01
        相关资源
        最近更新 更多