I have the following url which is created by Kentico to preview a page:
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");
}
}
}
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