0

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);
        }
    }
}
4

1 に答える 1

0

ODataQueryableSample ( http://www.asp.net/web-api/samples ) から、ODataException をスローすることが推奨される手法であることがわかります。試してみることをお勧めします。

ここにバグがあると思われる場合は、http://aspnetwebstack.codeplex.com/workitem/list/basicで新しいバグを報告することをお勧めします。

于 2013-10-15T16:16:30.767 に答える