1

既存の .aspx ページが要求を処理するように IHttpHandler を作成する適切な方法は何ですか? .aspx ファイルを IHttpHandler にコンパイルして、要求を処理できるようにしたいと考えています。PageParser.GetCompiledPageInstance メソッドがありますが、ドキュメントには、コードから直接使用するためのものではないと記載されています。apsx ファイルを自動的に転送したり、RewritePath を実行したりできることはわかっていますが、ハンドラーへのオブジェクト参照が必要です。

4

1 に答える 1

3

これを行う簡単な方法の 1 つを次に示します。

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);
于 2008-12-12T22:18:07.917 に答える