什么是正确的作出的IHttpHandler有一个现有的.aspx页面处理请求?我希望能够在.aspx文件编译成一个IHttpHandler的,然后把它处理请求。还有就是PageParser.GetCompiledPageInstance方法,但是在文档中它指出它不是从代码直接使用。我知道可以有apsx文件被自动引导到,或执行RewritePath,但是我想有对象参照处理程序。

有帮助吗?

解决方案

下面是这样做的一个快速N'-二肮脏的方式:

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top