I am developing some REST resources using the ASP.NET MVC 3 platform. So far, its been great, I love the flexibility of MVC 3, and it is a breeze to build REST services with it. One area where I have been having a difficult time are the route constraints in Global.asax. For one, they never seem to work properly (including one ALWAYS returns 404, even if the input most definitely meets the requirements of the constraint...but thats another question).
Second, and more importantly, the result returned when a constraint fails is always an HTML page. Assuming the constraints work, having the result be HTML really throws a wrench in the mix when all of the consumers of these REST services will be accepting data types, such as application/json, text/xml, possibly bson, etc. I really need to be able to address errors in our clients directly, rather than simply blowing up and logging the html for sideband resolution.
Is it possible to change what gets returned in response to a route constraint? Is it possible to make whats returned dynamic, such that if the client issuing the request only accepts application/bson, we can generate an acceptable response, rather than simply generating a canned response of a single mime type?