asp.net mvc 4 - Conditional filter: Only for controllers that inherit from baseController and is a post) -
how apply global filter actions controler inherits basecontroller
, post?
attempt
already working ninject.web.mvc aka ninject.web.mvc.filterbindingsyntax
but not know how apply conditional bindfilter
post.
kernel.bindfilter<validatejsonantiforgerytokenattribute>(system.web.mvc.filterscope.action, 0).whencontrollertype<basecontroller>();
...??
this attempt did not work, because not add 2 conditions bindfilter
i wanted similar this. 1 way implement multiple conditions inside of when()
. whencontrollertype()
method helper calls when()
, checks controller type, can re-implement in own method , add in whatever other logic need.
here how ninject implements whencontrollertype()
:
public ifilterbindinginnamedwithoronsyntax<t> whencontrollertype(type controllertype) { this.when((func<controllercontext, actiondescriptor, bool>) ((controllercontext, actiondescriptor) => (actiondescriptor.controllerdescriptor.controllertype == controllertype))); return this; }
from that, know how controller type our constraint.
to binding want, (untested):
kernel .bindfilter<validatejsonantiforgerytokenattribute>(system.web.mvc.filterscope.action, 0) .when((controllercontext, actiondescriptor) => controllercontext.httpcontext.request.requesttype.tolower() == "post" && typeof(basecontroller).isassignablefrom(actiondescriptor.controllerdescriptor.controllertype));
Comments
Post a Comment