So basically nice MVC routing. I think content provider only lets you find content that is in your actual tree and this content isn't. I am going to find it using C# in the DB and render a custom view and return it using a custom view model.
I know how to do the view part. Just need to know how to hijack all routes under a parent route so my base controller method hits without having to create a bunch of templates or action methods for each AD category type.
I did something similar to this using a content finder - adapting for your case I think it'll be something like this:
public bool TryFindContent(PublishedContentRequest request)
{
// We are looking for URLs of the form (/[ads landing page]/[parent category]/[child category]/
var urlParts = request.Uri.GetAbsolutePathDecoded().Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
if (urlParts.Length == 3)
{
// Check to see if request is below the ad landing page, if so do silent redirect to it passing the categories
var landingPageUrl = "/" + string.Join("/", urlParts[0]);
var firstLevelContent = request.RoutingContext.UmbracoContext.ContentCache.GetByRoute(landingPageUrl);
if (IsAdPage(firstLevelContent))
{
// Store the store Id in the HTTP context
HttpContext.Current.Items["parent"] = urlParts[1]; HttpContext.Current.Items["child"] = urlParts[2];
// Set the content to be the ads landing page - which will take us to our hijacked
// route controller to render the detail page
request.PublishedContent = firstLevelContent;
// Return true to indicate content found
return true;
}
}
return false;
}
Then in your controller you can check for the existing of those items in ControllerContext.HttpContext.Items["parent"] and ControllerContext.HttpContext.Items["child"] and do what you need to do with pulling the information from the external database.
How do I intercept all routes that have a base controller parent path in them in Umbraco 7
I have looked all around at Umbraco route hijacking and using IContentFinder and IUrlProvider and I am still a little lost on how to do what I want.
I have a controller that matches a document type which I have a base page for in Umbraco.
I made a document type called "Ads" and a controller called "AdsController: RenderMvcController"
I have a basic method to catch all like this
public ActionResult Index(RenderModel model)
It works if the route is like this
http://www.example.com/Ads?parent=Cars&child=American
but I want it to hit if I do this :
http://www.example.com/Ads/Cars/American
So basically nice MVC routing. I think content provider only lets you find content that is in your actual tree and this content isn't. I am going to find it using C# in the DB and render a custom view and return it using a custom view model.
I know how to do the view part. Just need to know how to hijack all routes under a parent route so my base controller method hits without having to create a bunch of templates or action methods for each AD category type.
Hi Kyle
I did something similar to this using a content finder - adapting for your case I think it'll be something like this:
Then in your controller you can check for the existing of those items in ControllerContext.HttpContext.Items["parent"] and ControllerContext.HttpContext.Items["child"] and do what you need to do with pulling the information from the external database.
Hope that helps.
Andy
is working on a reply...