Route hijacking route still valid after custom route implemented
I have added a custom route (/catalog/{x}/{y}) for my Product page. I can successfully use the custom route to view the page. However, when I navigate to /product I also see the Product page. I don't want the route hijacked route to work anymore. Is there a way to disable it?
I have a Product document type, ProductController that returns View("Product"), and Product.cshtml view.
public class CustomRoutingEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
var product = RouteTable.Routes.MapUmbracoRoute(
"Product",
"catalog/{x}/{y}",
new { controller = "product", action = "index" },
new CustomRouteNodeRouteHandler("product"));
}
}
public class CustomRouteNodeRouteHandler : UmbracoVirtualNodeRouteHandler
{
private string _documentTypeAlias;
public CustomRouteNodeRouteHandler(string documentTypeAlias)
{
_documentTypeAlias = documentTypeAlias;
}
protected override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext)
{
var helper = new UmbracoHelper(umbracoContext);
return helper.TypedContentAtRoot()
.First()
.Descendants()
.First(d => d.DocumentTypeAlias.InvariantEquals(_documentTypeAlias));
}
}
This associates the route catalog/{x}/{y} with my "Product" document type. Here is the controller for that page:
public class ProductController : RenderMvcController
{
public ActionResult Index(RenderModel renderModel, string x, string y)
{
var model = new ProductModel(renderModel.Content);
return View("Product", model);
}
}
Route hijacking route still valid after custom route implemented
I have added a custom route (/catalog/{x}/{y}) for my Product page. I can successfully use the custom route to view the page. However, when I navigate to /product I also see the Product page. I don't want the route hijacked route to work anymore. Is there a way to disable it?
I have a Product document type, ProductController that returns View("Product"), and Product.cshtml view.
Hi Megan,
Can you post the code on how you created the custom route and the code of your controller ?
That's easier to spot the issue.
Dave
Here is the custom route code:
This associates the route catalog/{x}/{y} with my "Product" document type. Here is the controller for that page:
Hi Megan,
What I would do in this case is setup a second action, for example product and use that for the virtual route.
Than in the index method I would return a 404 or redirect to the parent.
dave
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.