我刚刚部署了包含WebAPI的WCF Web服务。一切正常,直到我将自己的Filter Query Validator添加到我的项目中。然后角色继续回收和重新启动。这是一个非常奇怪的问题,我无法确定这是什么原因。谢谢你的帮助。
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.OData.Query;
using System.Web.Http.OData.Query.Validators;
using EMP.WebServices.api.Providers;
using Microsoft.Data.Edm.Library;
using Microsoft.Data.OData.Query.SemanticAst;
namespace EMP.WebServices.api.Validators
{
public class EntityFilterByQueryValidator : FilterQueryValidator
{
public override void ValidateSingleValuePropertyAccessNode(SingleValuePropertyAccessNode propertyAccessNode, ODataValidationSettings settings)
{
var declaringType = propertyAccessNode.Property.DeclaringType;
var edmEntityType = declaringType as EdmEntityType;
var allowedProperties = TableStorageProvider.GetMetadataPropertyNames(edmEntityType.Name,
Constants.WebApi.V1).ToList();
// Validate if we are accessing some sensitive property of WorkItem, such as Votes
if (!allowedProperties.Contains(propertyAccessNode.Property.Name))
{
throw new HttpResponseException(new HttpResponseMessage
{
Content = new StringContent(string.Format("{0} is an invalid filter property. {1}You can filter by these properties:{1}{2}.", propertyAccessNode.Property.Name, Environment.NewLine, string.Join(", " + Environment.NewLine, allowedProperties))),
ReasonPhrase = "Invalid Filter Property",
StatusCode = HttpStatusCode.BadRequest
});
}
base.ValidateSingleValuePropertyAccessNode(propertyAccessNode, settings);
}
}
}
答案 0 :(得分:0)
我从ODataQueryableSample(http://www.asp.net/web-api/samples)看到,抛出ODataException似乎是首选技术。我建议你尝试一下。
如果您认为此处存在错误,建议您在http://aspnetwebstack.codeplex.com/workitem/list/basic报告新错误。