4
我已经使用OpenRasta构建了一项服务。我正在验证操作拦截器中的资源。如果验证失败,则以ErrorResource返回BadRequest作为JSON。 ErrorResource包含错误消息列表。在我的本地机器上,ErrorResource以JSON格式正确返回。响应内容类型是application/json。在我们的测试环境中,服务使用BadRequest响应,但内容类型为text/html。错误消息的列表不会被返回。相反,响应包含消息“错误的请求”。任何想法为什么发生这种情况?OpenRasta坏请求不会返回为JSON
这里是拦截器的简化版本:
public override bool BeforeExecute(IOperation operation)
{
var errorResource = new ErrorResource();
errorResource.AddErrorMessage("Error!");
_communicationContext.OperationResult = new OperationResult.BadRequest() { ResponseResource = errorResource };
return false;
}
下面是配置的简化版本:在IIS
using (OpenRastaConfiguration.Manual)
{
ResourceSpace.Has
.ResourcesOfType<ErrorResource>()
.WithoutUri
.AsJsonDataContract();
ResourceSpace.Uses.CustomDependency<IOperationInterceptor, InputValidationInterceptor>(DependencyLifetime.Transient);
}
您可以发布您的配置代码片断,其中显示了如何配置ErrorResource?还发布你的拦截器? – taylonr
我已经添加了上面的相关代码。就像我说的那样,它可以在我的机器上运行:-)但是不在我们的测试环境中:-( – JuniorDeveloper