Represents the data required to proxy a request to a surface controller for posted data
Inheritance: RouteDefinition
        /// <summary>
        /// Handles a posted form to an Rebel Url and ensures the correct controller is routed to and that
        /// the right DataTokens are set.
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="postedInfo"></param>
        /// <param name="renderModel"></param>
        /// <param name="routeDefinition">The original route definition that would normally be used to route if it were not a POST</param>
        protected virtual IHttpHandler HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo, IRebelRenderModel renderModel, RouteDefinition routeDefinition)
        {
         
            //set the standard route values/tokens
            requestContext.RouteData.Values["controller"] = postedInfo.ControllerName;
            requestContext.RouteData.Values["action"] = postedInfo.ActionName;            
            requestContext.RouteData.DataTokens["area"] = postedInfo.Area;

            IHttpHandler handler = new MvcHandler(requestContext);

            //ensure the surface id is set if found, meaning it is a plugin, not locally declared
            if (postedInfo.SurfaceId != default(Guid))
            {
                requestContext.RouteData.Values["surfaceId"] = postedInfo.SurfaceId.ToString("N");
                //find the other data tokens for this route and merge... things like Namespace will be included here
                using (RouteTable.Routes.GetReadLock())
                {
                    var surfaceRoute = RouteTable.Routes.OfType<Route>()
                        .Where(x => x.Defaults != null && x.Defaults.ContainsKey("surfaceId") &&
                            x.Defaults["surfaceId"].ToString() == postedInfo.SurfaceId.ToString("N"))
                        .SingleOrDefault();
                    if (surfaceRoute == null)
                        throw new InvalidOperationException("Could not find a Surface controller route in the RouteTable for id " + postedInfo.SurfaceId);
                    //set the 'Namespaces' token so the controller factory knows where to look to construct it
                    if (surfaceRoute.DataTokens.ContainsKey("Namespaces"))
                    {
                        requestContext.RouteData.DataTokens["Namespaces"] = surfaceRoute.DataTokens["Namespaces"];    
                    }
                    handler = surfaceRoute.RouteHandler.GetHttpHandler(requestContext);
                }
                
            }

            //store the original URL this came in on
            requestContext.RouteData.DataTokens["rebel-item-url"] = requestContext.HttpContext.Request.Url.AbsolutePath;
            //store the original route definition
            requestContext.RouteData.DataTokens["rebel-route-def"] = routeDefinition;

            return handler;
        }
Exemple #2
0
        /// <summary>
        /// Handles a posted form to an Rebel Url and ensures the correct controller is routed to and that
        /// the right DataTokens are set.
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="postedInfo"></param>
        /// <param name="renderModel"></param>
        /// <param name="routeDefinition">The original route definition that would normally be used to route if it were not a POST</param>
        protected virtual IHttpHandler HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo, IRebelRenderModel renderModel, RouteDefinition routeDefinition)
        {
            //set the standard route values/tokens
            requestContext.RouteData.Values["controller"] = postedInfo.ControllerName;
            requestContext.RouteData.Values["action"]     = postedInfo.ActionName;
            requestContext.RouteData.DataTokens["area"]   = postedInfo.Area;

            IHttpHandler handler = new MvcHandler(requestContext);

            //ensure the surface id is set if found, meaning it is a plugin, not locally declared
            if (postedInfo.SurfaceId != default(Guid))
            {
                requestContext.RouteData.Values["surfaceId"] = postedInfo.SurfaceId.ToString("N");
                //find the other data tokens for this route and merge... things like Namespace will be included here
                using (RouteTable.Routes.GetReadLock())
                {
                    var surfaceRoute = RouteTable.Routes.OfType <Route>()
                                       .Where(x => x.Defaults != null && x.Defaults.ContainsKey("surfaceId") &&
                                              x.Defaults["surfaceId"].ToString() == postedInfo.SurfaceId.ToString("N"))
                                       .SingleOrDefault();
                    if (surfaceRoute == null)
                    {
                        throw new InvalidOperationException("Could not find a Surface controller route in the RouteTable for id " + postedInfo.SurfaceId);
                    }
                    //set the 'Namespaces' token so the controller factory knows where to look to construct it
                    if (surfaceRoute.DataTokens.ContainsKey("Namespaces"))
                    {
                        requestContext.RouteData.DataTokens["Namespaces"] = surfaceRoute.DataTokens["Namespaces"];
                    }
                    handler = surfaceRoute.RouteHandler.GetHttpHandler(requestContext);
                }
            }

            //store the original URL this came in on
            requestContext.RouteData.DataTokens["rebel-item-url"] = requestContext.HttpContext.Request.Url.AbsolutePath;
            //store the original route definition
            requestContext.RouteData.DataTokens["rebel-route-def"] = routeDefinition;

            return(handler);
        }