ASP.net IHttpHandler执行.aspx文件
让IHttpHandler拥有一个现有的.aspx页面来处理请求的正确方法是什么?我希望能够将.aspx文件编译成IHttpHandler,然后让它处理请求。有PageParser.GetCompiledPageInstance方法,但是在文档中它声明它不可直接从代码中使用。我知道我可以自动将apsx文件定向到或执行重写路径,但是我希望将对象引用到处理程序。这里有一种快速的方法:ASP.net IHttpHandler执行.aspx文件,asp.net,ihttphandler,Asp.net,Ihttphandler,让IHttpHandler拥有一个现有的.aspx页面来处理请求的正确方法是什么?我希望能够将.aspx文件编译成IHttpHandler,然后让它处理请求。有PageParser.GetCompiledPageInstance方法,但是在文档中它声明它不可直接从代码中使用。我知道我可以自动将apsx文件定向到或执行重写路径,但是我希望将对象引用到处理程序。这里有一种快速的方法: var virtualPath = "~/foo/bar.aspx" var output = HttpContex
var virtualPath = "~/foo/bar.aspx"
var output = HttpContext.Current.Response.Output;
// Get the compiled page type (i.e. foo_bar_aspx)
Type controlType = BuildManager.GetCompiledType(virtualPath);
// "new()" it up
var pageInstance = Activator.CreateInstance(controlType);
// Execute it
HttpContext.Current.Server.Execute(pageInstance, output, true);