c# - Implementing IActionFilter -


i'm building below filter:

public class testflowfilter : filterattribute, iactionfilter {     public void onactionexecuted(actionexecutedcontext filtercontext)     {         var profileid = int.parse(claimsprincipal.current.getclaimvalue("userid"));         var appid = int.parse(filtercontext.routedata.values["id"].tostring());          if (profileid != 0 && appid != 0)         {             if (checkifvalid(profileid, appid))             {                  // redirect                  filtercontext.result = // url go             }         }     }      public void onactionexecuting(actionexecutingcontext filtercontext)     {     }  } 

i need onactionexecuted, since iactionfilter interface have implement them both. ok leave onactionexecuting blank if don't need happen, or need call base version mvc runs?

also in onactionexecuted method if checkifvalid true redirect user, if not don't anything. ok or need set property on filtercontext instead.

i need onactionexecuted, since iactionfilter interface have implement them both. ok leave onactionexecuting blank if don't need happen, or need call base version mvc runs?

leaving method body empty acceptable in case. looks good!

also in onactionexecuted method if checkifvalid true redirect user, if not don't anything, ok or need set property on filtercontext instead.

your filter fine. mvc offer different abstract base class called actionfilterattribute, implements these interfaces override needed. there's nice overview can read here. if derive class, filter attribute code simplified little bit:

public class testflowfilter : actionfilterattribute {     public override void onactionexecuted(actionexecutedcontext filtercontext)     {         var profileid = int.parse(claimsprincipal.current.getclaimvalue("userid"));         var appid = int.parse(filtercontext.routedata.values["id"].tostring());          if (profileid != 0 && appid != 0)         {             if (checkifvalid(profileid, appid))             {                 // redirect                 filtercontext.result = // url go             }         }     } } 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -