Search code examples
c#asp.net-mvcurl-routingkentico

Url not hitting any actions


I have the following url which is created by Kentico to preview a page:

http://localhost:63603/cmsctx/pv/administrator/culture/en-GB/wg/7c938312-f3b2-4c87-afc3-d6e113d59177/h/8eabc114188f83ff5c6697cf943093ddf80ab319e1312aad7260feabd68acc89/-/about-us?uh=2fb6ea5fcb0f72d0b8a68be30aeea6ca9b985c84d9a5e7a605a746f58f53afae

But it is not hitting any of my controllers or actions - in my Route config I have the following 2 routes:

// Kentico CMS Console Preview Route
routes.MapRoute(
    name: "Preview",
    url: "cmsctx/pv/{username}/culture/{culture}/wg/{workflowGuid}/h/{hash}/{*pathname}",
    defaults: new { controller = "Preview", action = "Index" });

// Default catch all route
routes.MapRoute(
    name: "Default",
    url: "{*pathname}",
    defaults: new { controller = "Alias", action = "CatchAll" });

I would expect the above url to hit the preview controller, or at the very least the catch all, but neither controller is being hit and I just get a 404 resource cannot be found.

Weirdly, if I remove the /-/ from the url or put a letter or number next to it /-1/, then the preview controller will be hit. Does anyone know why the /-/ is causing my code not to hit any controllers?

This is my preview controller:

public class PreviewController : Controller
{
    public ActionResult Index(PreviewModel model)
    {
        model = previewModelBuilder.GetPreviewModel(model);

        if (model.Page != null)
        {
            return View(model);
        }
        else
        {
            throw new HttpException(404, "Page not found");
        }
    }
}

Solution

  • Ok I have found this is to do with something Kentico does - in my Global.asax I have registered the following:

    ApplicationConfig.RegisterFeatures(ApplicationBuilder.Current);
    

    And this runs the following:

    public static void RegisterFeatures(ApplicationBuilder builder)
    {
        if (builder != null)
        {
            builder.UsePreview();
        }
    }
    

    Removing this allows my routing to kick in and the controller gets hit