不允许使用查询选项“格式".要允许它,请在 EnableQueryAttribute 或 QueryValidationSettings 上设置“AllowedQueryOptions"属性 [英] Query option 'Format' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings

查看:10
本文介绍了不允许使用查询选项“格式".要允许它,请在 EnableQueryAttribute 或 QueryValidationSettings 上设置“AllowedQueryOptions"属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Web API 控制器端点出现异常,如果您能帮助解决此问题,我将不胜感激.

I'm getting an exception on my Web API controller endpoint and I would appreciate some help solving it.

故事是这样的:

在我的 Web API 项目中,控制器公开以下端点:

In my Web API project, a controller exposes the following endpoints:

我的 Kendo UI Datagrid 发出以下请求:

My Kendo UI Datagrid makes the following request:

http://localhost:63865/api/employees/GetAll?$callback=jQuery21109420544053427875_1410883352953&%24inlinecount=allpages&%24format=json&%24top=5

我在验证请求中发送的 ODataQueryOptions 时收到此异常:

I'm getting this exception when validating the ODataQueryOptions sent in the request:

不允许查询选项格式".要允许它,请在 EnableQueryAttribute 或 QueryValidationSettings 上设置AllowedQueryOptions"属性.

Query option 'Format' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings.

但我已启用所有查询选项:

But I've enabled all query options:

[EnableQuery(AllowedQueryOptions=AllowedQueryOptions.All)]

我做错了什么?

推荐答案

终于搞清楚了!

创建 ODataValidationSettings 对象后,我需要将 AllowedQueryOptions 更改为 AllowedQueryOptions.All.默认情况下,除 Format 和 SkipToken 外,所有选项都在那里.

After creating the ODataValidationSettings object I needed to change the AllowedQueryOptions to AllowedQueryOptions.All. Be default all options are there except the Format and SkipToken.

无论如何,希望这可以帮助其他面临同样问题的人.

Anyway, hope this may help anyone else facing the same issue.

这篇关于不允许使用查询选项“格式".要允许它,请在 EnableQueryAttribute 或 QueryValidationSettings 上设置“AllowedQueryOptions"属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆