MapContentRoute routes to startpage

Vote:
 

Hi!

I have a  route that looks like this:

RouteTable.Routes.MapContentRoute(
                name: "Product - Regular",
                url: "{node}/{category}/{productnumber}/{action}/",
                defaults: new
                {
                    action = "index",
                    controller = "Product"
                },
                contentRootResolver: (s) => s.StartPage
            );

As you can see I want it to route all pages localhost/category/productnumber/ to ProductController. This works, if I were to visit a product that exists. However, if I were to type in localhost/test/test (where test does not exist as a category) it automatically routes to the StartController instead. I obviously don't want this behaviour, instead I would like it to show a 404 page since that would most likely be the case.

I've solved this in a hacky manner for now, by in the StartController adding a parameter string category, and if category is not null or empty I will return a 404 page (this means that the route is triggered, but it routed to the StartController instead of ProductController):

public ActionResult Index(StartPage currentPage, string category = "")
{
        if (!string.IsNullOrEmpty(category))
            return HttpNotFound();
        ..//
}
#118315
Mar 04, 2015 10:39
Vote:
 

What ProductController looks like?

#118337
Mar 04, 2015 15:39
Vote:
 

Oh, obviously. I mixed it up with StartController and thought I already had it.

public class ProductController : PageControllerBase<ProductPage>
{
	public ActionResult Index(ProductPage currentPage, string category, string productnumber)
	{
		//...
	}
}

Where PageControllerBase derives from PageController<T> where T : SitePageData

#118388
Edited, Mar 05, 2015 12:54
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.