I've built a service using OpenRasta. I'm validating resources in a operation interceptor. If validation fails a BadRequest is returned with an ErrorResource as JSON. The ErrorResource contains a list of error messages. On my local machine the ErrorResource is returned correctly in JSON format. The response content type is application/json. On our test environment the service responds with a BadRequest but the content type is text/html. The list of error messages is not returned. Instead the resp开发者_开发知识库onse contains the message "Bad Request". Any ideas why this is happening?
Here is a simplified version of the interceptor:
public override bool BeforeExecute(IOperation operation)
{
var errorResource = new ErrorResource();
errorResource.AddErrorMessage("Error!");
_communicationContext.OperationResult = new OperationResult.BadRequest() { ResponseResource = errorResource };
return false;
}
Here is a simplified version of the configuration:
using (OpenRastaConfiguration.Manual)
{
ResourceSpace.Has
.ResourcesOfType<ErrorResource>()
.WithoutUri
.AsJsonDataContract();
ResourceSpace.Uses.CustomDependency<IOperationInterceptor, InputValidationInterceptor>(DependencyLifetime.Transient);
}
Disable error pages in IIS. There's some info in an email on the mailing list. See http://groups.google.com/group/openrasta/browse_thread/thread/50ac9048d8e4a77e/4977aab1334a3e60?#4977aab1334a3e60
精彩评论