Evaluating ASPX Pages from custom httpHandlers

I have search everywhere for help and its starting to annoy me.

I am creating an Internal Tooling Website which stores Tools and their related information.

My vision is to have a web address (Http://website.local/Tool/ID) Where ID is the ID of the Tool we want displayed. My reasoning is then I can extend the functionality of the URL to allow for various other functions.

Currently I use a custom httpHandler which intercepts any URL which is in the 'Tool' Folder.

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Tooling_Website.Tool
{
    public class ToolHandler : IHttpHandler
    {
        public bool IsReusable
        {
            get { return false; }
        }


        public void ProcessRequest(HttpContext context)
        {
            //The URL that would hit this handler is: http://{website}/Tool/{AN ID eg: http://{website}/Tool/PDINJ000500}
            //The idea is that what would be the page name is now the ID of the tool.
            //tool is an ASPX Page.
            tool tl = new tool();
            System.Web.UI.HtmlTextWriter htr = new System.Web.UI.HtmlTextWriter(context.Response.Output);
            tl.RenderControl(htr);
            htr.Close();
        }
    }
}

Basically I have a page inside the 'Tool' folder (Tool\tool.aspx) which I want my customer httpHandler to Render into the Response.

But this method doesn't work (It doesn't fail, just doesn't show anything) I can write the raw file to the response but obviously thats not my goal.

Thanks,

Oliver

Answers


If you still want to use your custom approach, you can try to do the following in your IHttpHandler derived class:

        public void ProcessRequest(HttpContext context)
        {
            //NOTE: here you should implement your custom mapping
            string yourAspxFile = "~/Default.aspx";
            //Get compiled type by path
            Type type = BuildManager.GetCompiledType(yourAspxFile);
            //create instance of the page
            Page page = (Page) Activator.CreateInstance(type);
            //process request
            page.ProcessRequest(context);
        }

Need Your Help

ASM - Intercepting field access made outside Method

java instrumentation java-bytecode-asm

I am currently using ASM to intercept all attempts to mutate field values in a target application this is working as expected as ASM allows you to prepend or append instructions to method or constr...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.