OpenRasta 错误请求不会以 JSON 形式返回
我使用 OpenRasta 构建了一项服务。我正在验证操作拦截器中的资源。如果验证失败,则会返回 BadRequest,并以 JSON 形式返回 ErrorResource。 ErrorResource 包含错误消息列表。在我的本地计算机上,ErrorResource 以 JSON 格式正确返回。响应内容类型为application/json。在我们的测试环境中,服务响应 BadRequest,但内容类型为 text/html。不返回错误消息列表。相反,响应包含消息“错误请求”。有什么想法为什么会发生这种情况吗?
这是拦截器的简化版本:
public override bool BeforeExecute(IOperation operation)
{
var errorResource = new ErrorResource();
errorResource.AddErrorMessage("Error!");
_communicationContext.OperationResult = new OperationResult.BadRequest() { ResponseResource = errorResource };
return false;
}
这是配置的简化版本:
using (OpenRastaConfiguration.Manual)
{
ResourceSpace.Has
.ResourcesOfType<ErrorResource>()
.WithoutUri
.AsJsonDataContract();
ResourceSpace.Uses.CustomDependency<IOperationInterceptor, InputValidationInterceptor>(DependencyLifetime.Transient);
}
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 response 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
禁用 IIS 中的错误页面。邮件列表上的电子邮件中有一些信息。请参阅http://groups.google.com/group/openrasta/browse_thread/thread/50ac9048d8e4a77e/4977aab1334a3e60?#4977aab1334a3e60
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