ASP.net IHttpHandler to execute .aspx file

What needs to be done to get the IHttpHandler to have an existing .aspx page to handle the request? I would like to compile an .aspx file into an IHttpHandler and then process the request. There is a PageParser.GetCompiledPageInstance method, however in the documentation it indicates that it is not intended to be used directly by code. I know that apsx files can be automatically redirected or executed by RewritePath, however I would like to have an object reference for the handler.

+1


source to share


1 answer


Here's one quick-n-dirty way to do it:



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

      

+3


source







All Articles