0

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);
        }
    }
}
Javier
  • 244
  • 1
  • 11
Jakub Holovsky
  • 6,543
  • 10
  • 54
  • 98

1 Answers1

0

I see from the ODataQueryableSample (http://www.asp.net/web-api/samples) that throwing an ODataException seems to be the preferred technique. I recommend you try that.

If you believe there is a bug here, I recommend you report a new bug at http://aspnetwebstack.codeplex.com/workitem/list/basic .

Ron Cain
  • 101
  • 2
  • Hello, I replace HttpRespExc with ODataException and the role still keeps recycling. Even if I try to put there dummy blank class the role keeps recycling. Like this: using System.Web.Http.OData.Query; using System.Web.Http.OData.Query.Validators; using Microsoft.Data.OData.Query.SemanticAst; namespace EMP.WebServices.api.Validators { public class EntityFilterByQueryValidator : FilterQueryValidator { public override void ValidateSingleValuePropertyAccessNode(SingleValuePropertyAccessNode propertyAccessNode, ODataValidationSettings settings) { } } } – Jakub Holovsky Oct 16 '13 at 01:07
  • I raised an issue at the mentioned address: https://aspnetwebstack.codeplex.com/workitem/1341 – Jakub Holovsky Oct 16 '13 at 01:34