【问题标题】:Azure - WebAPI + OData - FilterQueryValidator - Role Keeps recyclingAzure - WebAPI + OData - FilterQueryValidator - 角色保持循环
【发布时间】:2013-09-19 04:25:53
【问题描述】:

我刚刚部署了包含 WebAPI 的 WCF Web 服务。一切正常,直到我将自己的过滤器查询验证器添加到我的项目中。然后角色不断回收并重新启动。这是一个非常奇怪的问题,我无法确定这是什么原因。感谢您的帮助。

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

【问题讨论】:

  • 如果您仅出于测试目的删除异常的抛出,会发生什么?
  • 它仍在不断回收。如果我把全班都注释掉就好了。

标签: asp.net azure odata asp.net-web-api asp.net-web-api-odata


【解决方案1】:

我从 ODataQueryableSample (http://www.asp.net/web-api/samples) 中看到,抛出 ODataException 似乎是首选技术。我建议你试试。

如果您认为这里存在错误,我建议您在 http://aspnetwebstack.codeplex.com/workitem/list/basic 报告新错误。

【讨论】:

  • 你好,我把 HttpRespExc 替换为 ODataException 并且角色仍然在循环。即使我尝试将虚拟空白类放在那里,角色也会不断回收。像这样:使用 System.Web.Http.OData.Query;使用 System.Web.Http.OData.Query.Validators;使用 Microsoft.Data.OData.Query.SemanticAst;命名空间 EMP.WebServices.api.Validators { public class EntityFilterByQueryValidator : FilterQueryValidator { public override void ValidateSingleValuePropertyAccessNode(SingleValuePropertyAccessNode propertyAccessNode, ODataValidationSettings settings) { } } }
  • 我在提到的地址提出了一个问题:aspnetwebstack.codeplex.com/workitem/1341
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-22
  • 2016-08-02
  • 2013-06-02
  • 2013-04-19
  • 1970-01-01
  • 2014-12-29
  • 1970-01-01
相关资源
最近更新 更多