Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 19, 2010 08:53 AM by mad-halfling
Mar 18, 2010 05:06 PM|LINK
Your code seems sound. A few comments:
Would the controller and action name ever not exist/get passed in? I couldn't see any reason why not, but I was wondering - even if it were a default action, from the URL's point of view, this would still generate an action name in the RouteData, wouldn't
You can get the controller and action name from filterContext (filterContext.ActionDescriptor.ActionName and filterContext.ActionDescriptor.ControllerDescriptor.ControllerName). This should be easier than going through RouteData. And you're guaranteed
that they're set. So that else block after the DB call isn't necessary.
Also, output caching is something that's explicitly stated, isn't it? As you suggested, and as far as I am aware, I am not explicitly using it (nor would I want to as each page in this app is always dynamic) but are there any gotchas that I can check for that
might enable it somehow?
Using [OutputCache] or calling the output caching methods are the only ways to enable it. The first few lines where output caching is disabled is just a precaution in case an [OutputCache] inadvertently gets set on this controller.
Mar 18, 2010 11:27 PM|LINK
Thanks for the feedback - I don't have ActionDescription as an available property/method on the filterContext object - all I have are Controller, Equals, GetHashCode, GetType, HttpContext, RequestContext, Result, RouteData, ToString - what am I missing?
Had figured that about the output cache, but wanted to check it couldn't sneak in anywhere - thanks for clarifying that.
Mar 19, 2010 12:21 AM|LINK
I don't have ActionDescription as an available property/method on the filterContext object
It's available in MVC 2 (as of Beta or RC1, I think?). If you're using MVC 1, use RouteData.GetRequiredString() instead. This is the same as RouteData.Values, but it performs the null-or-empty check for you.
Mar 19, 2010 08:53 AM|LINK
Ah, I was wondering about that after I logged off last night - yes I'm still on 1 (complicated app + deadline = not-upgrading-yet). No matter, it works OK and I've put a comment in the program that it can be changed when the framework is upgraded. Thanks
for all your help, you are a gent and a scholar.