Last post Sep 13, 2008 04:21 PM by timtas
Sep 04, 2008 12:21 AM|bulgarian388|LINK
So, I just upgraded to preview 5, and now my filters are broken... One of my filters makes sure that the url contains "www" (for search engine consistency) and it uses the ActionMethod.Name property to make sure its redirecting to the proper action. Alas,
the ActionMethod is now gone, so I don't know what I should use to find out what action was being accessed, or if it's even possible...
If anyone has any ideas, I would appreciate them.
Thanks in advance!
Sep 04, 2008 12:39 AM|flukus|LINK
Sep 04, 2008 07:56 AM|levib|LINK
The ActionMethod property is gone per the discussion at
http://forums.asp.net/p/1301069/2538397.aspx. If you need to access the controller name or the action name
and you're using standard MVC naming conventions for routes, you can access them from the filter context via RouteData.Values["controller"] and RouteData.Values["action"].
Sep 13, 2008 03:42 PM|timtas|LINK
Yesterday I discovered this breaking change. I have made a workaround like so:
var method = filterContext.Controller.GetType()
This feels really yucky and in fact will break if I ever want to use the AcceptVerbs attribute to translate routes into differently named methods. Does anyone know a more sure way to do this?
In case anyone is wondering, "why do you want the method anyway," I will explain. My site has a main menu and I need to always know which menu item represents the current context. To achieve this I set a filter attribute for each method that identifies
its "menu context." To get the attrubute I need to know the current executing method. Maybe there is some other (better?) way to achieve this?
Sep 13, 2008 04:21 PM|timtas|LINK
Never mind about my question of a better way to do this. I have found it. Actually I had a a filter attribute on the class, SetMainMenu, and a normal attribute on the methods, MenuContext("Products"). SetMainMenu reflected on the calling method to get
the MenuContext attribute and setup the menu correctly.
Now MenuContext is a filter attribute which then comes behind SetMainMenu and disables the the current menu item based on its key. No need for reflection. A better approach.