Evaluating ASPX Pages from Custom HTTPHandlers

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

I am creating an internal toolkit website that stores the Tools and their related information.

My vision is to have a web address (Http: //website.local/Tool/ID) Where ID is the identifier of the tool we want to display. My reasoning is that I can extend the functionality of the URL to use various other functions.

I am currently using a custom httpHandler that intercepts any URL that 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) that I want my httpHandler client to display the response.

But this method does not work (it does not fail, it just shows nothing). I can write the raw file in response, but obviously this is not my goal.

Thanks,

Oliver

+6
source share
1 answer

If you still want to use your own approach, you can try 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);
         }
+5
source

Source: https://habr.com/ru/post/904048/


All Articles