asp.net mvc - ActionFilterAttribute mvc need to call One time -
i have scenario need check security each menu item if user 'a' allowed access menu or not , reason created class inherited actionfilterattribute
public class securityfilter : actionfilterattribute { public override void onactionexecuting(actionexecutingcontext filtercontext) { log("onactionexecuting", filtercontext.routedata); } }
and using class on controller
[securityfilter] public class xyzcontroller : controller { public actionresult index() { homecoming view(); } }
now problem in view have @html.action() calls e.g
@html.action("com")
which results in calling onactionexecuting method again, want phone call 1 time when menu link clicked , method menu redirecting not other action method render within view
when called using @html.action
ischildaction
property of filtercontext
true. can rely on determine whether want or not:
public override void onactionexecuting(actionexecutingcontext filtercontext) { if (filtercontext.ischildaction) return; log("onactionexecuting", filtercontext.routedata); }
see msdn
asp.net-mvc asp.net-mvc-4 action action-filter actionfilterattribute
No comments:
Post a Comment