/// <summary> /// Sets the ControllerContext and UrlHelper on the destination controller if the types given have those properties available. /// </summary> /// <param name="controller"></param> /// <param name="proxyController"></param> /// <param name="action"></param> /// <param name="area">If the proxying should be to a different area, specify the area name</param> private static ControllerContext InjectControllerPropertiesForProxying( this ControllerBase controller, ControllerBase proxyController, MethodInfo action, string area = "") { //clone new route data to to execute the action var routeData = controller.ControllerContext.RouteData.Clone(); if (!area.IsNullOrWhiteSpace()) { routeData.DataTokens["area"] = area; } routeData.Values["action"] = action.Name; routeData.Values["controller"] = UmbracoController.GetControllerName(proxyController.GetType()); var isChildAction = action.GetCustomAttributes(typeof(ChildActionOnlyAttribute), false).Any(); if (isChildAction) { //this is how the controller context determines if it is rendering a child action //we need to pass in the current (Parent) controller's ViewContext object routeData.DataTokens["ParentActionViewContext"] = controller.ControllerContext.CreateEmptyViewContext(); } //create a new controller context to execute the proxied action var ctrlContext = new ControllerContext(controller.ControllerContext.HttpContext, routeData, proxyController); proxyController.ControllerContext = ctrlContext; if (proxyController is Controller && controller is Controller) { ((Controller)proxyController).Url = ((Controller)controller).Url; } return(ctrlContext); }
/// <summary> /// Returns the url for searching using JSON /// </summary> /// <param name="url"></param> /// <returns></returns> public static string GetTreeSearchUrl(this UrlHelper url) { var appTreeControllerName = UmbracoController.GetControllerName(typeof(ApplicationTreeController)); var appTreeControllerId = UmbracoController.GetControllerId <TreeAttribute>(typeof(ApplicationTreeController)); return(url.Action("Search", appTreeControllerName, new { area = url.GetBackOfficeArea(), treeId = appTreeControllerId.ToString("N") })); }
/// <summary> /// Returns the default dashboard url /// </summary> /// <param name="url"></param> /// <param name="appAlias">The application (i.e. content) to render the dashboard for</param> /// <returns></returns> public static string GetDashboardUrl(this UrlHelper url, string appAlias) { var dashboardControllerName = UmbracoController.GetControllerName(typeof(DashboardEditorController)); var dashboardControllerId = UmbracoController.GetControllerId <EditorAttribute>(typeof(DashboardEditorController)); return(url.Action("Dashboard", dashboardControllerName, new { editorId = dashboardControllerId.ToString("N"), appAlias = appAlias })); }
/// <summary> /// Returns the full unique url for a Tree based on it's type /// </summary> /// <param name="url"></param> /// <param name="action"></param> /// <param name="treeType"></param> /// <param name="id"></param> /// <param name="queryStrings"></param> /// <returns></returns> public static string GetTreeUrl(this UrlHelper url, string action, Type treeType, HiveId id, FormCollection queryStrings) { if (!treeType.GetCustomAttributes(typeof(TreeAttribute), false).Any()) { throw new InvalidCastException("The controller type specified is not of type TreeController"); } return(url.GetTreeUrl(action, id, UmbracoController.GetControllerId <TreeAttribute>(treeType), queryStrings)); }
//public static string GetEditorUrl(this UrlHelper url, Type controllerType, object id) //{ // return url.GetEditorUrl("Edit", controllerType, id); //} /// <summary> /// Returns the full unique url for an Editor based on it's type /// </summary> public static string GetEditorUrl(this UrlHelper url, string action, Type controllerType, HiveId?id) { if (!controllerType.GetCustomAttributes(typeof(EditorAttribute), false).Any()) { throw new InvalidCastException("The controller type specified is not decorated with an EditorAttribute"); } var componentRegistrations = DependencyResolver.Current.GetService <ComponentRegistrations>(); var settings = DependencyResolver.Current.GetService <UmbracoSettings>(); return(url.GetEditorUrl(action, id, UmbracoController.GetControllerId <EditorAttribute>(controllerType), componentRegistrations, settings)); }
/// <summary> /// Returns the dashboard Url for a specified controller /// </summary> /// <param name="url"></param> /// <param name="controllerType"></param> /// <param name="appAlias">The application (i.e. content) to render the dashboard for</param> /// <returns></returns> public static string GetDashboardUrl(this UrlHelper url, Type controllerType, string appAlias) { Mandate.ParameterNotNull(controllerType, "controllerType"); if (!controllerType.GetCustomAttributes(typeof(EditorAttribute), false).Any()) { throw new InvalidCastException("The controller type specified is not of type BaseEditorController"); } return(url.Action("Dashboard", UmbracoController.GetControllerName(controllerType), new { editorId = UmbracoController.GetControllerId <EditorAttribute>(controllerType).ToString("N"), appAlias = appAlias })); }
public override ActionResult Execute( Content currentNode, IDictionary <string, string> macroParams, MacroDefinition macro, ControllerContext currentControllerContext, IRoutableRequestContext routableRequestContext) { MethodInfo childAction; var surfaceController = macro.GetSurfaceMacroChildAction(routableRequestContext.RegisteredComponents, out childAction); if (!TypeFinder.IsTypeAssignableFrom <PartialViewResult>(childAction.ReturnType) && !TypeFinder.IsTypeAssignableFrom <ContentResult>(childAction.ReturnType)) { throw new InvalidOperationException("ChildAction macros should have a return type of " + typeof(PartialViewResult).Name + " or " + typeof(ContentResult).Name); } using (var controller = surfaceController.Value) { if (controller == null) { throw new TypeLoadException("Could not create controller: " + UmbracoController.GetControllerName(surfaceController.Metadata.ComponentType)); } //need to get the macroParams to put into an array var actionParams = macroParams.Select(i => i.Value).ToArray(); var area = routableRequestContext.Application.Settings.UmbracoPaths.BackOfficePath; if (surfaceController.Metadata.PluginDefinition.HasRoutablePackageArea()) { area = surfaceController.Metadata.PluginDefinition.PackageName; } //proxy the request to the controller var result = currentControllerContext.Controller.ProxyRequestToController(controller, childAction, area, actionParams); return(result); } }
public IMembershipHelperWrapper GetMembershipHelperWrapper(UmbracoController controller) { return(new MembershipHelperWrapper(controller)); }