Question

I'm working on a small school project, an ASP.NET C# website; we're working with a Web Application, using a Global.asax file to centralize request logic.

Anyway, my colleague and I are responsible for the coding in our group, and we both come as reasonably experienced PHP developers. We both rather enjoy working with the architectural style used by the PHP framework Laravel, using routes (callbacks associated with) as the "controllers", and (despite it being a square peg, round hole issue) are trying to replicate that functionality for this project.

This is no easy task; I've implemented the IRouteHandler interface as a CallbackRouteHandler in an attempt to start replicating this functionality:

public class CallbackRouteHandler : IRouteHandler
{
    public Func<RequestContext, IHttpHandler> Callback { get; protected set; }

    public CallbackRouteHandler(Func<RequestContext, IHttpHandler> callback)
    {
        this.Callback = callback;
    }

    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        return this.Callback(requestContext);
    }
}

Unfortunately this is about as far as I've gotten. I'm reading through the ASP.NET Page Life Cycle Overview, attempting to understand better the entire process.

What we're stuck on is programmatically loading ASPX files (rather, instantiating as Page objects) in the scope of a given route callback. We were hoping there would be a reasonably easy way to accomplish, within the scope of the callback, something like:

// instantiate the target ASPX page object
OurSite.SomeNamespace.SomePage page = new OurSite.SomeNamespace.SomePage();

// manipulate the page object, setting public properties, etc.
page.SomeControl.Text = "Foobar!";

// eventually "render" the file to somehow; at this point, the
// page and it's associated code-behind events take control
page.Render();

I'm having trouble understanding both: 1) How to do this? 2) When (relative to the aforementioned page life-cycle) to do this.

How (if at all) can one accomplish this sort of functionality? I'm seeing that this process, hidden away by ASP.NET, is seemingly very complicated, but surely others have tread down this path before.

Was it helpful?

Solution

I went with MVC for this project, however I've since had the opportunity to dissect the ASP.NET request pipeline a bit, and have implemented custom routing solutions as warranted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top