c# - Get the Class name in a class with atribute inside a attribute method -


i'm doing custom authorize attribute.

want use attribute in class , controller level.

this code work on method level

public class customauthorizeattribute : authorizeattribute {      public customauthorizeattribute([callermembername] string callername = null)     {         callername = callername;     }      public string callername { get; set; }      protected override bool authorizecore(httpcontextbase httpcontext)     {         if (httpcontext.user.isinrole("admin"))             return true;          ...         if (callername == something)         {                     }         ...          return base.authorizecore(httpcontext);     } } 

like that

    [customauthorize()]     public actionresult index()     {         return view();     } 

but want use globally in controller

[customauthorize()] public class usuarioscontroller : controller {     salusdbcontext db = new salusdbcontext();       // get: usuarios     public actionresult index()     {         return view();     } } 

sorry bad english.

in end didn't need reflection or fancy, in authorizeattribute have httpcontext, can route, controller , action name.

public class customauthorizeattribute : authorizeattribute {      protected override bool authorizecore(httpcontextbase httpcontext)     {         var routevalues = httpcontext.request.requestcontext.routedata.values;          if (httpcontext.user.isinrole("admin"))             return true;          var controller = routevalues["controller"];         var action = routevalues["action"];          return base.authorizecore(httpcontext);     } } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -