Skip to content

Instantly share code, notes, and snippets.

@sniffdk
Created October 8, 2015 07:07
Show Gist options
  • Save sniffdk/1eb694c7421e52ee4b1d to your computer and use it in GitHub Desktop.
Save sniffdk/1eb694c7421e52ee4b1d to your computer and use it in GitHub Desktop.
Snippet to demo how to intercept the Umbraco route hijacking before a suitable controller is found
using System;
using System.Web.Routing;
using Umbraco.Web.Mvc;
public class CustomRenderControllerFactory : RenderControllerFactory
{
// Attempt to resolve an alternative controller
// This methods is called for all controllers in the request pipeline including surface controllers and possibly third party controllers.
// We need to make sure we only hijack the actual Umbraco page request.
public override Type GetControllerType(RequestContext requestContext, string controllerName)
{
var routeData = requestContext.RouteData;
if (routeData.DataTokens.ContainsKey("controller") && routeData.DataTokens["controller"].Equals("RenderMvc"))
{
// Add your own logic
if(controllerName == "ThatController")
{
controllerName = "ThisController";
}
}
return base.GetControllerType(requestContext, controllerName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment