I am trying to implement a custom AuthorizeAttribute for a WEB API. Things have been going good so far, however I am stuck trying to find a way to prevent the username/password credentials box coming up when a user is not authorized. I am overriding the "HandleUnauthorizedRequest" method like so:
protected override void HandleUnauthorizedRequest(HttpActionContext actionContext)
{
base.HandleUnauthorizedRequest(actionContext);
actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Unauthorized");
}
This, however does not work. I can change the status code to Forbidden, which will prevent the prompt from showing, however I don't think that is the "right way of doing things" solution.
I don't want this prompt to show because I am making a call from a client using JavaScript. I want to receive the 401 and handle it on the client side.
Can someone explain to me what I am missing? (or let me know if I should be using Forbidden ?)
Thanks