I'm using Phil Haack's URL routing for WebForms and I would like to define a route that's "dynamic." Let's say I have this route:
"{any}.aspx" -- goes to --> "~/PageProcessor.aspx"
This would take any request that's not a physical page to the PageProcessor page. This works great. The problem is that, based on some data that comes from a database, I need certain pages to be routed to a different processor, let's say DifferentPageProcessor.aspx. I can't define a new route that catches all the .aspx files because the first one catches everything.
So, I would need a way to process the request before the "router" decides to take it to PageProcessor and fork it to either PageProcessor or DifferentPageProcessor as needed. Is this possible?
Thanks.
It's in VB but this is how I do it:
This does the same as yours, it catches the entire request but it then passes it off to my own custom route handler class:
In my example I have overloaded System.ui.page so that every aspx page in my project can inherit certain properties automatically like for example the mySettings object which contains my apps settings.. This is why I dim page as myCustom_Page_Base, you can load it as a standard page.
The important bit is: BuildManager.CreateInstanceFromVirtualPath method this will load whatever aspx file you point to it..
Hope this helps..
My solution -- unless somebody comes up with a more elegant one -- was to modify the WebFormRouteHandler class in the WebFormRouting project to accept a custom predicate.
Then inside the class I would store the custom parameter into private CustomVirtualPath property. To use it, I had to change GetSubstitutedVirtualPath to this:
For the project to compile we need to change WebFormRoute and WebFormRouteExtensions to allow the passing of the custom parameter down the chain. When all done I can write this in global.asax.cs
Of course the body of the lambda expression should look up the URL from some other place (database or cache).