I'm doing a Custom Authorize Attribute.
Want use this Attribute in class and controller level.
This code work on a 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)
{
do this
}
...
return base.AuthorizeCore(httpContext);
}
}
like that
[CustomAuthorize()]
public ActionResult Index()
{
return View();
}
But i want use globally in a controller
[CustomAuthorize()]
public class UsuariosController : Controller
{
SalusDbContext db = new SalusDbContext();
// GET: Usuarios
public ActionResult Index()
{
return View();
}
}
Sorry the bad English.
Aucun commentaire:
Enregistrer un commentaire