c# - How to use public property in actioninvoke in asp.net mvc? -


i have code

public actionresult index() {      if (currentuser != null)      {             usermanager.user usr = (user.user)currentuser;      } } 

i have done admincontroller : testcontroller

now way access currentuser in actioninvoke use check user admin or not

 public class adminauthorize : actionfilterattribute      {         public override void onresultexecuting(resultexecutingcontext filtercontext)         {             base.onresultexecuting(filtercontext);         }     } 

is anyway use currentuser variable in invoker.

you should able access current controller instance controller property of filtercontext.

public class adminauthorize : actionfilterattribute  {     public override void onresultexecuting(resultexecutingcontext filtercontext)     {         base.onresultexecuting(filtercontext);          var currentuser = ((admincontroller)filtercontext.controller).currentuser;          // need currentuser     } } 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -