I've just deployed WCF web service that includes WebAPI as well. Everything works fine until I add my own Filter Query Validator to my project. Then the role keeps recycling and restarting. It's a very strange issue, I am unable to determine what is the cause of this. Thank you for any help.
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);
}
}
}