title: Sending json response using Authentication filter in Web api controller?
body: <p>I have an authentication filter in my controller </p>
  
  <pre><code>[ArcGISAuthentication]
  </code></pre>
  
  <p>I have defined the filter like below</p>
  
  <pre><code>public class ArcGISAuthenticationAttribute : Attribute, IAuthenticationFilter
  {
      public Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
      {
          return Task.Run(async () =&gt;
          {
              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(() =&gt; { });
      }
  
      public ArcGISAuthenticationAttribute()
      {
  
      }
  }
  </code></pre>
  
  <p>The problem is I want to send a json repsonse when the authentication fail. As in the else statement in the AuthenticateAsync above.</p>
  
  <p>How can I do this? </p>