I have a controller which should only request authorization when loaded with specific parameters. Like when the parameter ID is 8 for example.
I came up with using a custom validation attribute like this:
public class MyAuthorizeAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (/* Action's inputparameter ID = 8 */)
{
return base.AuthorizeCore(httpContext);
}
return true;
}
}
My action looks like this (not that it is interesting)
[MyAuthorize]
public ActionResult Protected(int id)
{
/* custom logic for setting the viewmodel from the id parameter */
return View(viewmodel);
}
The problem is as you can see that I don't know how to check for that ID parameter in the authorize attribute. Can you help me with a solution?