I have an authentication filter in my controller
[ArcGISAuthentication]
I have defined the filter like below
public class ArcGISAuthenticationAttribute : Attribute, IAuthenticationFilter
{
public Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
{
return Task.Run(async () =>
{
var queryParameters = HttpUtility.ParseQueryString(context.Request.RequestUri.Query);
var token = queryParameters["token"];
if (!string.IsNullOrWhiteSpace(token))
{
var userInfo = await CommunityManager.GetUserInfoAsync(token);
context.Principal = new ArcGISUserPrincipal(userInfo, token);
context.Request.SetUserPrincipal(context.Principal);
}
else{
//What shoudld I do here to send a json response
}
});
}
public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
{
return Task.Run(() => { });
}
public ArcGISAuthenticationAttribute()
{
}
}
The problem is I want to send a json repsonse when the authentication fail. As in the else statement in the AuthenticateAsync above.
How can I do this?