views:

153

answers:

1

Ok... got URL Routing working just fine, but cannot figure out how to actually read the values in the target page.

One example here shows using the RouteValue object from the RequestContext. Now all of these are in the System.Web.Routing namespace, but everyone seems to be connecting these to MVC only. Where does the RequestContext come from?

How do I read these parameters???

Querystring is blank as well.

TIA! Kevin

A: 

Solved this one on my own... Yay me!!! :)

Started mucking around with things and saw the IHttpHandler interface provides the RequestContext to the GetHttpHandler method.

So, I modified my base page class (I always put a layer between System.Web.UI.Page and my own pages, calling it BasePage or similar just for the purpose). So I added a public property on PVBasePage to receive a RequestContext object.

public RequestContext RequestContext { get; set; }

Then, my Routing class code is as follows:

IHttpHandler IRouteHandler.GetHttpHandler(RequestContext requestContext)
{
    // create the page object as my own page...
    var page = BuildManager.CreateInstanceFromVirtualPath(VirtualPath
        , typeof(PVBasePage)) as PVBasePage;
    // pass in the request context
    page.RequestContext = requestContext;
    // return this page in the form of a IHttpHandler
    return page as IHttpHandler;
}

So instead of, as in the sample code, creating the instance directly as the IHttpHandler, I create it as my own page. Set the request context property, and then return the page to the caller AS a IHttpHandler.

Tested and it works. WOO HOO!

Hope this helps someone else down the road.

peiklk