I noticed the ActionNameAttribute lets you alias your controller methods. This is nice but I was curious if there was a comparable attribute for a controller name. Specifically, I have a controller with a lengthy name in c# world but would like to shorten
/ alias it in the actual URL. I was hoping for some kind of controllername attribute. Is there such a beast?
We've thought about it, but it's not a very high priority for us right now as it would change our controller caching and invocation systems in a non-trivial manner. We're playing around with systems that would allow more dynamic selection of controllers
and actions beyond what a [ControllerName] attribute could accomplish, but there's nothing yet to report on that front.
There's a workaround for what you wanted:
public class FriendlyNameController : MyReallyReallyLongControllerNameController { }
Routing is probably your simplest solution if you only have a handfult of these cases.
routes.MapRoute( "Shorthand", // Route name "ShortName/{action}/{id}", // URL with parameters new { controller = "LongName", action = "Index", id = "" } // Parameter defaults );
If you have lots and you just want to use the default route you then could: 1) create a custom attribute that defines the short name 2) add it to your controllers 3) Reflect over your assembly types on app startup and register custom default route for each type substitutting in the shortname
Paul
http://pabloblamirez.blogspot.com - When you ask a question, remember to click "mark as answered" when you get a reply which answers your question; this ensures the right forum member gets credit below for being helpful (and makes search more relevant too).
Marked as answer by skmcfadden on Feb 01, 2010 11:02 PM
skmcfadden
Member
35 Points
97 Posts
short hand name attribute for controller?
Feb 01, 2010 04:57 PM|LINK
I noticed the ActionNameAttribute lets you alias your controller methods. This is nice but I was curious if there was a comparable attribute for a controller name. Specifically, I have a controller with a lengthy name in c# world but would like to shorten / alias it in the actual URL. I was hoping for some kind of controllername attribute. Is there such a beast?
thanks!
controller shorthand naming
ignatandrei
All-Star
134521 Points
21576 Posts
Moderator
MVP
Re: short hand name attribute for controller?
Feb 01, 2010 08:27 PM|LINK
No that I have seen. But nothing stops you to write a ControllerMethodSelector (as I suppose the ActionMethodSelectorAttribute does the work)!
And then write to ASP.NET MVC team about!
levib
Star
7702 Points
1099 Posts
Microsoft
Re: short hand name attribute for controller?
Feb 01, 2010 10:56 PM|LINK
We've thought about it, but it's not a very high priority for us right now as it would change our controller caching and invocation systems in a non-trivial manner. We're playing around with systems that would allow more dynamic selection of controllers and actions beyond what a [ControllerName] attribute could accomplish, but there's nothing yet to report on that front.
There's a workaround for what you wanted:
public class FriendlyNameController : MyReallyReallyLongControllerNameController { }
PaulBlamire
Participant
1272 Points
227 Posts
Re: short hand name attribute for controller?
Feb 01, 2010 10:58 PM|LINK