Render a page inside of an HttpModule?

拟墨画扇 提交于 2019-12-01 11:34:57

You can do something like this:

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

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.

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