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

conditions full image

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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -