Exemplo n.º 1
0
        /// <summary>
        /// Handles a posted form to an Umbraco 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>
        private IHttpHandler HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo)
        {
            //set the standard route values/tokens
            requestContext.RouteData.Values["controller"] = postedInfo.ControllerName;
            requestContext.RouteData.Values["action"]     = postedInfo.ActionName;

            IHttpHandler handler;

            //get the route from the defined routes
            using (RouteTable.Routes.GetReadLock())
            {
                Route surfaceRoute;
                if (postedInfo.Area.IsNullOrWhiteSpace())
                {
                    //find the controller in the route table without an area
                    surfaceRoute = RouteTable.Routes.OfType <Route>()
                                   .SingleOrDefault(x => x.Defaults != null &&
                                                    x.Defaults.ContainsKey("controller") &&
                                                    x.Defaults["controller"].ToString() == postedInfo.ControllerName &&
                                                    !x.DataTokens.ContainsKey("area"));
                }
                else
                {
                    //find the controller in the route table with the specified area
                    surfaceRoute = RouteTable.Routes.OfType <Route>()
                                   .SingleOrDefault(x => x.Defaults != null &&
                                                    x.Defaults.ContainsKey("controller") &&
                                                    x.Defaults["controller"].ToString().InvariantEquals(postedInfo.ControllerName) &&
                                                    x.DataTokens.ContainsKey("area") &&
                                                    x.DataTokens["area"].ToString().InvariantEquals(postedInfo.Area));
                }

                if (surfaceRoute == null)
                {
                    throw new InvalidOperationException("Could not find a Surface controller route in the RouteTable for controller name " + postedInfo.ControllerName);
                }

                //set the area if one is there.
                if (surfaceRoute.DataTokens.ContainsKey("area"))
                {
                    requestContext.RouteData.DataTokens["area"] = surfaceRoute.DataTokens["area"];
                }

                //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);
            }

            return(handler);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles a posted form to an Umbraco 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="routeDefinition">The original route definition that would normally be used to route if it were not a POST</param>
        private IHttpHandler HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo, RouteDefinition routeDefinition)
        {
            var standardArea = Umbraco.Core.Configuration.GlobalSettings.UmbracoMvcArea;

            //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 controllerType is set if found, meaning it is a plugin, not locally declared
            if (postedInfo.Area != standardArea)
            {
                //requestContext.RouteData.Values["controllerType"] = postedInfo.ControllerType;
                //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>()
                                       .SingleOrDefault(x => x.Defaults != null &&
                                                        x.Defaults.ContainsKey("controller") &&
                                                        x.Defaults["controller"].ToString() == postedInfo.ControllerName &&
                                                        x.DataTokens.ContainsKey("area") &&
                                                        x.DataTokens["area"].ToString() == postedInfo.Area);
                    if (surfaceRoute == null)
                    {
                        throw new InvalidOperationException("Could not find a Surface controller route in the RouteTable for controller name " + postedInfo.ControllerName + " and within the area of " + postedInfo.Area);
                    }
                    //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["umbraco-item-url"] = requestContext.HttpContext.Request.Url.AbsolutePath;
            //store the original route definition
            requestContext.RouteData.DataTokens["umbraco-route-def"] = routeDefinition;

            return(handler);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles a posted form to an Umbraco 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>
        private IHttpHandler HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo)
        {
            //set the standard route values/tokens
            requestContext.RouteData.Values["controller"] = postedInfo.ControllerName;
            requestContext.RouteData.Values["action"]     = postedInfo.ActionName;

            IHttpHandler handler = new MvcHandler(requestContext);

            //ensure the controllerType is set if found, meaning it is a plugin, not locally declared
            if (!postedInfo.Area.IsNullOrWhiteSpace())
            {
                //requestContext.RouteData.Values["controllerType"] = postedInfo.ControllerType;
                //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>()
                                       .SingleOrDefault(x => x.Defaults != null &&
                                                        x.Defaults.ContainsKey("controller") &&
                                                        x.Defaults["controller"].ToString().InvariantEquals(postedInfo.ControllerName) &&
                                                        x.DataTokens.ContainsKey("area") &&
                                                        x.DataTokens["area"].ToString().InvariantEquals(postedInfo.Area));
                    if (surfaceRoute == null)
                    {
                        throw new InvalidOperationException("Could not find a Surface controller route in the RouteTable for controller name " + postedInfo.ControllerName + " and within the area of " + postedInfo.Area);
                    }

                    requestContext.RouteData.DataTokens["area"] = surfaceRoute.DataTokens["area"];

                    //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);
                }
            }

            return(handler);
        }
Exemplo n.º 4
0
		/// <summary>
		/// Handles a posted form to an Umbraco 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>
		private IHttpHandler HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo)
		{
			//set the standard route values/tokens
			requestContext.RouteData.Values["controller"] = postedInfo.ControllerName;
			requestContext.RouteData.Values["action"] = postedInfo.ActionName;

			IHttpHandler handler = new MvcHandler(requestContext);

			//ensure the controllerType is set if found, meaning it is a plugin, not locally declared
			if (!postedInfo.Area.IsNullOrWhiteSpace())
			{
				//requestContext.RouteData.Values["controllerType"] = postedInfo.ControllerType;
				//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>()
						.SingleOrDefault(x => x.Defaults != null &&
						                      x.Defaults.ContainsKey("controller") &&
						                      x.Defaults["controller"].ToString().InvariantEquals(postedInfo.ControllerName) &&
						                      x.DataTokens.ContainsKey("area") &&
						                      x.DataTokens["area"].ToString().InvariantEquals(postedInfo.Area));
					if (surfaceRoute == null)
						throw new InvalidOperationException("Could not find a Surface controller route in the RouteTable for controller name " + postedInfo.ControllerName + " and within the area of " + postedInfo.Area);
                    
                    requestContext.RouteData.DataTokens["area"] = surfaceRoute.DataTokens["area"];
                    
                    //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);
				}

			}

			return handler;
		}
Exemplo n.º 5
0
        /// <summary>
        /// Handles a posted form to an Umbraco 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>
        internal static IHttpHandler HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo)
        {
            if (requestContext == null)
            {
                throw new ArgumentNullException(nameof(requestContext));
            }
            if (postedInfo == null)
            {
                throw new ArgumentNullException(nameof(postedInfo));
            }

            //set the standard route values/tokens
            requestContext.RouteData.Values["controller"] = postedInfo.ControllerName;
            requestContext.RouteData.Values["action"]     = postedInfo.ActionName;

            IHttpHandler handler;

            //get the route from the defined routes
            using (RouteTable.Routes.GetReadLock())
            {
                Route surfaceRoute;

                //find the controller in the route table
                var surfaceRoutes = RouteTable.Routes.OfType <Route>()
                                    .Where(x => x.Defaults != null &&
                                           x.Defaults.ContainsKey("controller") &&
                                           x.Defaults["controller"].ToString().InvariantEquals(postedInfo.ControllerName) &&
                                           // Only return surface controllers
                                           x.DataTokens["umbraco"].ToString().InvariantEquals("surface") &&
                                           // Check for area token if the area is supplied
                                           (postedInfo.Area.IsNullOrWhiteSpace() ? !x.DataTokens.ContainsKey("area") : x.DataTokens["area"].ToString().InvariantEquals(postedInfo.Area)))
                                    .ToList();

                // If more than one route is found, find one with a matching action
                if (surfaceRoutes.Count > 1)
                {
                    surfaceRoute = surfaceRoutes.FirstOrDefault(x =>
                                                                x.Defaults["action"] != null &&
                                                                x.Defaults["action"].ToString().InvariantEquals(postedInfo.ActionName));
                }
                else
                {
                    surfaceRoute = surfaceRoutes.FirstOrDefault();
                }

                if (surfaceRoute == null)
                {
                    throw new InvalidOperationException("Could not find a Surface controller route in the RouteTable for controller name " + postedInfo.ControllerName);
                }

                //set the area if one is there.
                if (surfaceRoute.DataTokens.ContainsKey("area"))
                {
                    requestContext.RouteData.DataTokens["area"] = surfaceRoute.DataTokens["area"];
                }

                //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);
            }

            return(handler);
        }
Exemplo n.º 6
0
		/// <summary>
		/// Handles a posted form to an Umbraco 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>
		private IHttpHandler HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo)
		{
		    if (requestContext == null) throw new ArgumentNullException("requestContext");
		    if (postedInfo == null) throw new ArgumentNullException("postedInfo");

		    //set the standard route values/tokens
			requestContext.RouteData.Values["controller"] = postedInfo.ControllerName;
			requestContext.RouteData.Values["action"] = postedInfo.ActionName;

            IHttpHandler handler;
            
            //get the route from the defined routes
		    using (RouteTable.Routes.GetReadLock())
		    {
		        Route surfaceRoute;
		        if (postedInfo.Area.IsNullOrWhiteSpace())
		        {
                    //find the controller in the route table without an area
		            surfaceRoute = RouteTable.Routes.OfType<Route>()
		                                         .SingleOrDefault(x => x.Defaults != null &&
		                                                               x.Defaults.ContainsKey("controller") &&
		                                                               x.Defaults["controller"].ToString() == postedInfo.ControllerName &&
		                                                               !x.DataTokens.ContainsKey("area"));                    
		        }
                else
		        {
                    //find the controller in the route table with the specified area
		            surfaceRoute = RouteTable.Routes.OfType<Route>()
		                                         .SingleOrDefault(x => x.Defaults != null &&
		                                                               x.Defaults.ContainsKey("controller") &&
						                      x.Defaults["controller"].ToString().InvariantEquals(postedInfo.ControllerName) &&
		                                                               x.DataTokens.ContainsKey("area") &&
						                      x.DataTokens["area"].ToString().InvariantEquals(postedInfo.Area));                    
		        }

                if (surfaceRoute == null)
                    throw new InvalidOperationException("Could not find a Surface controller route in the RouteTable for controller name " + postedInfo.ControllerName);
                
                //set the area if one is there.
                if (surfaceRoute.DataTokens.ContainsKey("area"))
                {
                    requestContext.RouteData.DataTokens["area"] = surfaceRoute.DataTokens["area"];
                }

                //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);

		    }

			return handler;
		}
Exemplo n.º 7
0
		/// <summary>
		/// Handles a posted form to an Umbraco 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="routeDefinition">The original route definition that would normally be used to route if it were not a POST</param>
		private IHttpHandler HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo, RouteDefinition routeDefinition)
		{
			var standardArea = Umbraco.Core.Configuration.GlobalSettings.UmbracoMvcArea;

			//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 controllerType is set if found, meaning it is a plugin, not locally declared
			if (postedInfo.Area != standardArea)
			{
				//requestContext.RouteData.Values["controllerType"] = postedInfo.ControllerType;
				//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>()
						.SingleOrDefault(x => x.Defaults != null &&
						                      x.Defaults.ContainsKey("controller") &&
						                      x.Defaults["controller"].ToString() == postedInfo.ControllerName &&
						                      x.DataTokens.ContainsKey("area") &&
						                      x.DataTokens["area"].ToString() == postedInfo.Area);
					if (surfaceRoute == null)
						throw new InvalidOperationException("Could not find a Surface controller route in the RouteTable for controller name " + postedInfo.ControllerName + " and within the area of " + postedInfo.Area);
					//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["umbraco-item-url"] = requestContext.HttpContext.Request.Url.AbsolutePath;
			//store the original route definition
			requestContext.RouteData.DataTokens["umbraco-route-def"] = routeDefinition;

			return handler;
		}