title: asp.net mvc [handleerror] [authorize] with JsonResult?
body: <p>What is an elegant way to leverage the existing [HandleError] and [Authorize] attributes when dealing with XHR calls from javascript?</p>
  
  <p>So, say for example a method GetJson which returns a JsonResult.</p>
  
  <p>When an error occurs, the [HandleError] method will send back a ViewResult which will be retrived in the callback function in javascript.</p>
  
  <p>I'd then have to place custom code everywhere in javascript to handle and redirect any crashes, etc.</p>
  
  <p>What I'd like to do, is have the [HandleError] attribute return a JsonResult if the original action was planning to do that.  This might be wishful thinking on my part.</p>
  
  <p>Similarly, if an unauthorized Json request comes in, instead of returning a new HttpUnauthorizedResult I'd like to return a JsonResult that allows my client side code to handle things in a common manner.</p>
  
  <p>Am I barking up the wrong tree here?  Maybe there's an even nicer way that MVC can handle this which I'm unaware of?</p>
  
  <p>How are other people handling this scenario?</p>
  
  <p>Thanks.</p>
  
  <p>PS: I realize I can create my own [HandleJsonError] and [AuthorizeJson] attributes which return JsonResults instead of ViewResults, but then I'd have to go around and place these on any method that returns Json, and worry about Filter order etc.  It sure would be nice if I could use reflection or something to have the same attribute act differently depending on the signature of the original method.</p>