0
votes

I am really stuck on a problem that did not seem to be a problem at all at first, but I really cant get it to work. So I am hoping someone out there can shed som light on my problem.

So here is the deal, I have a site that is running Umbraco version 7.6.4 assembly: 1.0.6396.36621.

And my problem here is that I want to use a custom controller with a action method so the url will be:

http://example.com/CONTROLLER/ACTION/SOME_KIND_OF_ID I need it to be a surtain specific url because this site will replace an old site and I will need to do some redirecting back to the old site IF surtain specific IDs will come as a parameter to that routing URL.

I have come so far that I have hijacked the routing so I can get the Index method to work with my controller when I load specific page on the site. But that only goes so far to http://example.com/CONTROLLER/ and nothing else - I want to be able to trigger the specified ACTION-name as well! (Not sure that is the right way to go at all)

I have created a page in Umbraco with the same name as the controller.

And I do need to have the default Umbraco routing to work for the rest of the site. I just need to gain access to the specific controller/action/ID :)

I really do hope that someone out there can give me a helping hand!

Best Regards, Daniel

1

1 Answers

2
votes

You could use the RouteTable.Routes.MapRoute on the event

IApplicationEventHandler.OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
      RouteTable.Routes.MapRoute("NameTheRoute", "{controller}/{action}/{id}",
                                 new { 
                                       controller = "YourController",
                                       action = "YourAction", 
                                       id = UrlParameter.Optional
                                     });
    }

You can link your controllers and surface controllers.