I would expect it to return "true" or "false" ...
I overridden OnAuthorization in my controller and based on missing or invalid HTTP header value. I want to return the 403 ban, however, I cannot figure out how to return anything from OnAuthorization so that it actually stops the rest of the controller launch.
What should I do?
My first attempt below was a huge failure, I think Deny () works, but nothing happens ...
public class AuthController : Controller
{
protected override void OnAuthorization(AuthorizationContext filterContext)
{
if (string.IsNullOrEmpty(filterContext.HttpContext.Request.Headers["Authorization"]))
Deny();
string authString = filterContext.HttpContext.Request.Headers["Authorization"];
base.OnAuthorization(filterContext);
}
private ActionResult Deny()
{
HttpContext.Response.StatusCode = 403;
return Content("Access Denied", "text/plain");
}
}
UPDATE looks like it's a trick, for some reason, why could this be a bad approach?
if (string.IsNullOrEmpty(filterContext.HttpContext.Request.Headers["Authorization"]))
{
filterContext.Result = Content("Access Denied", "text/plain");
filterContext.HttpContext.Response.StatusCode = 403;
base.OnAuthorization(filterContext);
}
UPDATE AGAIN ok, ... , INTO if base.OnAuthorization(...) call, ... if, ? , base.OnAuthorization(...) ?