Copied to clipboard

Flag this post as spam?

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


  • Wendelin Niesl 6 posts 56 karma points
    Jun 22, 2015 @ 13:23
    Wendelin Niesl
    0

    Custom Controller and Subdomains

    Hey there,

    I'm new to Umbraco and just getting started with the basics, so please forgive me if I'm asking stupid questions :)

    My scenario is following: I have a mixed Website. On the one hand, there is Umbraco with all the content etc. and on the other hand we have a rich web application with several database connections.

    So far there is nothing wrong with it but now I made a custom controller that should prepare a custom model for one document type.

    My doc type structure looks kinda:

    1. de

      • products
      • news
      • etc.
    2. en

      • Products
      • News
      • etc.

    And all my paths to the contents look somehow like: "localhost/de/products" "localhost/en/news"

    So when creating the custom "ProductsController", the only path that is working with it, is "localhost/products"

    Is there a chance to make the custom controller catch the right route? E.g. "localhost/de/products"

    Thanks for any help!

  • Doron Uziel 23 posts 93 karma points
    Jun 22, 2015 @ 14:11
    Doron Uziel
    0

    Hi,

    Hope I understand your problem correctly.

    What you are looking for is called Route Hijacking.

    Basically by inheriting from RenderMvcController and calling your controller after your doctype alias (that is for Product Doctype - ProductController), You are able to hijack the route and perform whatever custom logic required.

    I suggest you read the link above and see if it makes sense to you.

  • Wendelin Niesl 6 posts 56 karma points
    Jun 22, 2015 @ 14:40
    Wendelin Niesl
    0

    Hi,

    thanks for answering :)

    Yes, I have already read the tutorial but I can't figure out how to let Umbraco route the whole path to my controller.

    So I have the "ProductsController" that should be responsible for the Route "de/products", according to my Document Type Structure:

    1. de
      • products
      • news
      • etc.

    But Umbraco only matches the route "/products" with my Custom Controller. When trying to access "/de/products" I keep getting an 404 error.

    Is there any additional Route Configuration that I need to implement? Until now I have only created the document type and the ProductController that inherits from "RenderMvcController".

    Thanks!

  • Doron Uziel 23 posts 93 karma points
    Jun 22, 2015 @ 15:27
    Doron Uziel
    0

    Not sure I follow you. Let me see if I understand your state correctly:

    1. You have a DocType named Products.
    2. You also have a Content Node called Products under another content called De. This content has the above document type of Products (that is both the content node as well as its document type are called Products).
    3. You have a controller called ProductsController, that inherits from RenderMvcController that looks something along the line of:

      public class HomeController : Umbraco.Web.Mvc.RenderMvcController { public override ActionResult Index(RenderModel model) { //Do some stuff here..... }

      }

    Yet when you call /de/products the Index ActionResult is not triggered.

    Am I correct ?

  • Doron Uziel 23 posts 93 karma points
    Jun 22, 2015 @ 15:30
    Doron Uziel
    0

    Sorry for the messed up code in 3, it should be:

    public class ProductsController : Umbraco.Web.Mvc.RenderMvcController
    {
        public override ActionResult Index(RenderModel model)
        {
            //Do some stuff here.......
        }
    
    }
    
  • Wendelin Niesl 6 posts 56 karma points
    Jun 22, 2015 @ 16:08
    Wendelin Niesl
    0

    Okay, i think i should expand it to it's real complexity. I have imported a lot of content from another cms, structuring everything into Content Types for "de" and "en".

    This is an excerpt from my content type structure:

    enter image description here

    This is my content type area

    So every content type's alias is for example "produktvorstellungende" or "produktvorstellungenen".

    enter image description here

    This is my content area:

    This is my content area

    "Product Presentations" is the content for "Produktvorstellungen" (The alias of Produktvorstellungen is "produktvorstellungenen" in this case) And all of it's subnodes have the same content type "Produktvorstellungen". So i should also have 2 Controllers, ProduktvorstellungenenController and Produktvorstellungen_deController.

    My controllers look like:

       public class Produktvorstellungen_enController : RenderMvcController
       {
           public ActionResult Show(RenderModel model)
           { // Some cool stuff here
              return CurrentTemplate(newModel)
           }
        }
    

    And i have the Template "Show"

    @inherits UmbracoViewPage<Company.Models.ProductPresentationContentModel>
    @{
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    

    So I don't know whether this is going to help or it's just making everything more difficult but I don't know how i can explain it in other words :)

    At the moment I'm only trying to make it run with 1 controller.

Please Sign in or register to post replies

Write your reply to:

Draft