Created
October 8, 2015 07:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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