IsValidControllerType does not support Controller classes that use generics (CMS MVC controller) #1158

Imported from the CodePlex archive for reference purposes. Support for MvcCodeRouting has ended.

Reported on

Attempting to use MvcCodeRouting with controllers that use generics breaks with code routing in MvcCodeRouting.RegisterSetting.IsValidControllerType() beacuse it is inspecting the type.Name property instead of doing a true type comparison of [type is Controller]. If the controller uses generics the Type.Name property returns “Controller~1” which fails this validity check.

&& type.Name.EndsWith(“Controller”, StringComparison.OrdinalIgnoreCase);

Requesting that this change can be made so that we can use code routing with our CMS controllers.

Commented on link

If I remember correctly, DefaultControllerFactory requires that controllers use the “Controller” suffix, that’s why MvcCodeRouting also checks for that. A type comparison is also done on the IsMvcController method, see here.

Generic controllers are not allowed because: a- doesn’t work with DefaultControllerFactory; b- No way to determine what is the correct controller name. Any ideas about this?

You can work around this limitation defining controllers that inherit the generic controller type (e.g. see this).