'How to get Controller Name, customize and find View folder ASP.NET MVC 6

(For education purposes)

I'm trying to change convention ControllerName for render View.

By default, controllers use convention "Name" + "Controller", and then ASP.NET looking for View folder "Name".

I want change this convention. For example: "Name" + "Foo", cut "Name" pass and render View folder "Name".

Suppose you need create new convention. "HomeFoo" controller must work with View folder "emoH" - reversed name controller. For this need take path "Home" from controller name, reverse and pass for next operation.

How can this be implemented?

I'm tried implement this with IControllFactory, but I don't know what to do next:

    internal class CustomFactoryController : IControllerFactory
    {
  
        public object CreateController(ControllerContext context)
        {
           
            string controllerName = context.ActionDescriptor.ControllerName;

            // here reverse Controller name
            // context.ActionDescriptor.ControllerName = controllerNameReversed;

            // and next create controller with new Context. How can this be implemented?


        }
        public void ReleaseController(ControllerContext context, object controller)
        {

        }
    }

Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source