Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • jlacis 19 posts 39 karma points
    Jan 08, 2013 @ 09:15
    jlacis
    0

    custom routing

    Hello.

    I need to set up custom Ruotes. 

    I made this, according to this documentation: http://our.umbraco.org/documentation/Reference/Mvc/custom-routes

    so, my global assax file is 

    <%@ Application Codebehind="Global.asax.cs" Inherits="MySite.MvcApplication" Language="C#" %>

    and cs file is 

     

      public class MvcApplication : Umbraco.Web.UmbracoApplication

        {

            public static void RegisterGlobalFilters(GlobalFilterCollection filters)

            {

                filters.Add(new HandleErrorAttribute());

            }

            public static void RegisterRoutes(RouteCollection routes)

            {

                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

     

                routes.MapRoute(

                    "Default", // Route name

                    "{controller}/{action}/{id}", // URL with parameters

                    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults

                  // Parameter defaults

                );

                routes.MapRoute(

                    "Pipe", // Route name

                    "{controller}/{action}/{id}", // URL with parameters

                    new {controller = "Pipe", action = "Index", id = UrlParameter.Optional});

            }

            protected override void OnApplicationStarted(object sender, EventArgs e)

            {

                base.OnApplicationStarted(sender, e);

                RegisterRoutes(RouteTable.Routes);

            }

            protected void Application_Start()

            {

                AreaRegistration.RegisterAllAreas();

           RegisterGlobalFilters(GlobalFilters.Filters);

            }

        }

     

    after that my custom route works but, if I want to view other pages of my site, I see an empty page.

    custom route's adding to umbracoReservedUrls or umbracoReservedPaths did not help to resolve the problem

    <add key="umbracoReservedUrls" value="~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd, ~/Pipe/Index.aspx" />

        <add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/Pipe/" />

    Please, help

     

  • jlacis 19 posts 39 karma points
    Jan 09, 2013 @ 17:50
    jlacis
    0

    up fot this topic.

    I realy need to fix this asap :( 

  • Keith Jackson 183 posts 552 karma points
    Feb 02, 2013 @ 11:38
    Keith Jackson
    0

    From the looks of it your first route definition is catching everything pretty much {controller}/{action}/{id} - That's why your site doesn't work.

    You need to use a more specific route definition 'pipe/{id}' for example

  • nojaf 91 posts 300 karma points
    Nov 26, 2013 @ 15:50
    nojaf
    0

    Any luck with this? I'm in a situation where I want an custom MVC controller (and not one that inherits RenderMvcController)

     

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Nov 28, 2013 @ 11:56
    Tim
    0

    Have a look at the blog post listed at the bottom of the docs here: https://github.com/umbraco/Umbraco4Docs/blob/master/Documentation/Reference/Templating/Mvc/custom-routes.md Shannons blog post goes into a bit more detail about custom routes, maybe something on there will help?

  • nojaf 91 posts 300 karma points
    Nov 28, 2013 @ 14:26
    nojaf
    1

    Yes indeed, that does the trick.

    Using something like:

        public void OnApplicationStarted(
            UmbracoApplicationBase umbracoApplication, 
            ApplicationContext applicationContext)
        {
            //Create a custom route
            RouteTable.Routes.MapRoute(
                "test",
                "Products/{action}/{id}",
                new
                    {
                        controller = "MyProduct", 
                        action = "Product", 
                        id = UrlParameter.Optional
                    });           
        }
    And the fun thing is, that your ProductsController is allowed the extend Mvc.Controller and doesn't have to be an UmbracoRenderController
  • Proxicode 128 posts 324 karma points
    Oct 03, 2017 @ 20:01
    Proxicode
    1

    This helped me a lot! Thank you for sharing!

  • satjinder 16 posts 28 karma points
    May 06, 2014 @ 11:47
    satjinder
    0

    hi @nojaf,

    I have tried it on Umbraco 7 and getting some issues, what I have tried so far is:

    1) Created MVC project and added a controller into it

    2) Added routes as OnApplicationStarted in global.asax.cs.

    3) Compiled and copied the DLL to umraco website's bin folder

    4) Copied Views to hte Views folder

     

    Now when i try go to my controller i.e. http:\\localhost\Test\Index, it gives me 404.

     

    What have I missed?

     

    Thanks in advance

    Satjinder

     

  • nojaf 91 posts 300 karma points
    May 06, 2014 @ 12:57
    nojaf
    0

    I think step 2 isn't correct, you should add the route in a custom Umbraco Event class. Create an ApplicationEventHandler and try adding the route there.

Please Sign in or register to post replies

Write your reply to:

Draft