在 HttpModule 内渲染页面?

发布于 2024-08-11 23:54:50 字数 47 浏览 2 评论 0原文

有人知道如何在 HttpModule 中渲染 aspx 页面并将其流回浏览器吗?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

摘星┃星的人 2024-08-18 23:54:50

你可以这样做:

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

You can do something like this:

Type page_type = BuildManager.GetCompiledType ("~/page.aspx");
Page page = (Page) Activator.CreateInstance (page_type);
page.ProcessRequest (Context);
我一向站在原地 2024-08-18 23:54:50
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());
    }
}
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());
    }
}
半暖夏伤 2024-08-18 23:54:50

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

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文