Created
February 17, 2014 23:59
-
-
Save sbosell/9061807 to your computer and use it in GitHub Desktop.
Umbraco Angular Default Controller
This file contains 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
namespace MvcApplication1.Controllers | |
{ | |
public class DefaultController : Umbraco.Web.Mvc.RenderMvcController | |
{ | |
// | |
// GET: /Default/ | |
public ActionResult Index(AngRenderModel model) | |
{ | |
model.isApp = UmbracoContext.Current.HttpContext.Request.Headers["app"] != null; | |
return base.Index(model); | |
} | |
} | |
public class CustomControllerFactory : RenderControllerFactory | |
{ | |
public override IController CreateController(RequestContext requestContext, string controllerName) | |
{ | |
var instance = base.CreateController(requestContext, controllerName); | |
var controllerInstance = instance as Controller; | |
if (controllerInstance != null) | |
{ | |
controllerInstance.ActionInvoker = new CustomRenderActionInvoker(); | |
} | |
return instance; | |
} | |
} | |
public class CustomRenderActionInvoker : ControllerActionInvoker | |
{ | |
protected override ActionDescriptor FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, string actionName) | |
{ | |
var ad = base.FindAction(controllerContext, controllerDescriptor, actionName); | |
if (ad == null) | |
{ | |
if (controllerContext.Controller is RenderMvcController) | |
{ | |
return new ReflectedActionDescriptor( | |
controllerContext.Controller.GetType().GetMethods().First(x => | |
x.Name == "Index" && | |
!x.GetCustomAttributes(typeof(NonActionAttribute), false).Any()), | |
"Index", | |
controllerDescriptor | |
); | |
} | |
} | |
return ad; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment