public void OnViewCreated(ControllerContext context, Type type, object view) { if (view is RenderViewPage) { var renderView = view as RenderViewPage; var renderModel = _renderModelFactory.Create(context.HttpContext, context.RequestContext.HttpContext.Request.RawUrl); var routableRequestContext = this.GetRoutableRequestContextFromSources(view, context); //set the RenderViewPageContext of the view renderView.RenderViewPageContext = new RenderViewPageContext(context) { RenderModel = renderModel, RoutableRequestContext = routableRequestContext, RenderModelFactory = _renderModelFactory, Umbraco = new UmbracoHelper(context, routableRequestContext, _renderModelFactory) }; //add the context to the HttpContext Items so it can be resolved if necessary by a RenderViewPage if it is not created //with this activator... this will occur for any Layout files that inherit from RenderViewPage because layout files are //created differently in MVC. if (!context.HttpContext.Items.Contains(typeof(RenderViewPageContext).Name)) { context.HttpContext.Items.Add(typeof(RenderViewPageContext).Name, renderView.RenderViewPageContext); } } }
public override bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { var includeExcludeMatch = base.Match(httpContext, route, parameterName, values, routeDirection); if (includeExcludeMatch) { //TODO: We need to add a local cache to this class for every route that comes in that doesn't match a current node we need to cache // that somewhere so we don't have lookup the node again, otherwise for normal MVC requests this will always attempt to lookup // an item. //need to ensure the application is installed, if not then don't route this request if (!_applicationContext.AllProvidersInstalled()) { return(false); } //ensure theres content to route to var renderModel = _modelFactory.Create(httpContext, httpContext.Request.RawUrl); if (renderModel == null || renderModel.CurrentNode == null) { return(false); } } return(includeExcludeMatch); }
public ActionResult Index(string macroAlias) { return(RenderMacro(macroAlias, () => { var currentContext = _renderModelFactory.Create(HttpContext, HttpContext.Request.RawUrl); return currentContext.CurrentNode; })); }
public UmbracoHelper(ControllerContext controllerContext, IRoutableRequestContext requestContext, IRenderModelFactory modelFactory) { _requestContext = requestContext; _controllerContext = controllerContext; _modelFactory = modelFactory; _currentPage = _modelFactory.Create(_controllerContext.HttpContext, _controllerContext.HttpContext.Request.RawUrl).CurrentNode; _urlHelper = new UrlHelper(_controllerContext.RequestContext); }
/// <summary> /// Assigns the correct controller based on the Umbraco request and returns a standard MvcHandler to prcess the response, /// this also stores the render model into the data tokens for the current RouteData. /// </summary> /// <param name="requestContext"></param> /// <returns></returns> public IHttpHandler GetHttpHandler(RequestContext requestContext) { // Generate a render model var renderModel = _modelFactory.Create(requestContext.HttpContext, requestContext.HttpContext.Request.RawUrl); //put the render model into the current RouteData requestContext.RouteData.DataTokens.Add("umbraco", renderModel); return(GetHandlerForRoute(requestContext, renderModel)); }
public RebelHelper(ControllerContext controllerContext, IRoutableRequestContext requestContext, IRenderModelFactory modelFactory) { _requestContext = requestContext; _controllerContext = controllerContext; _modelFactory = modelFactory; _currentPage = _modelFactory.Create(_controllerContext.HttpContext, _controllerContext.HttpContext.Request.RawUrl).CurrentNode; _urlHelper = new UrlHelper(_controllerContext.RequestContext); }
/// <summary> /// Binds the model to a value by using the specified controller context and binding context. /// </summary> /// <returns> /// The bound value. /// </returns> /// <param name="controllerContext">The controller context.</param><param name="bindingContext">The binding context.</param> public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var requestMatchesType = typeof(IRebelRenderModel).Equals(bindingContext.ModelType); if (requestMatchesType) { return(_modelFactory.Create(controllerContext.HttpContext, controllerContext.HttpContext.Request.RawUrl)); } return(null); }