DefaultInlineContraintResolver错误的WebAPI 2 [英] DefaultInlineContraintResolver Error in WebAPI 2

查看:1788
本文介绍了DefaultInlineContraintResolver错误的WebAPI 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Web API 2,我收到以下错误,当我发个帖子在我的本地主机使用的是IIS 7.5我的API的方法。

I'm using Web API 2 and I'm getting the following error when I send a POST to my API method using IIS 7.5 on my local box.

The inline constraint resolver of type 'DefaultInlineConstraintResolver' was unable to resolve the following inline constraint: 'string'.

Line 21: GlobalConfiguration.Configuration.EnsureInitialized();

我做工的API使用IIS的无。不过,我可以使用IIS防爆preSS运行在Visual Studio我的API项目,并成功地使一个后到我的登录API,但是当我试图使一个GET请求到另一个API调用,我得到的约束解析错误。

None of my APIs work using IIS. However, I'm able to run my API project in Visual Studio using IIS Express and successfully make a POST to my login API, but when I try and make a GET request to another API call, I get the constraint resolver error.

为了解决这个问题,我创造了在Visual Studio中一个全新的Web API 2项目,并开始导入现有的API为同时新的项目之一,并运行它们,以确保他们的工作。使用IIS防爆preSS这个新项目,我得到完全相同的结果,因为我用我现有的API项目做到了。

In order to troubleshoot this, I created a brand new Web API 2 project in Visual Studio and started importing the existing APIs into the new project one at a time and running them to ensure they work. Using IIS Express with this new project, I get the same exact results as I did with my existing API project.

我缺少的是在这里吗?即使有一个全新的项目,我无法使GET请求,而不会在此约束解析问题。

What am I missing here? Even with a brand new project I'm not able to make GET requests without running into this constraint resolver issue.

推荐答案

由于错误表示,在 DefaultInlineConstraintResolver 该Web API附带没有所谓的内嵌约束字符串。默认支持的是以下内容:

As the error indicates, the DefaultInlineConstraintResolver that Web API ships with does not have an inline constraint called string. The default supported ones are the following:

// Type-specific constraints
{ "bool", typeof(BoolRouteConstraint) },
{ "datetime", typeof(DateTimeRouteConstraint) },
{ "decimal", typeof(DecimalRouteConstraint) },
{ "double", typeof(DoubleRouteConstraint) },
{ "float", typeof(FloatRouteConstraint) },
{ "guid", typeof(GuidRouteConstraint) },
{ "int", typeof(IntRouteConstraint) },
{ "long", typeof(LongRouteConstraint) },

// Length constraints
{ "minlength", typeof(MinLengthRouteConstraint) },
{ "maxlength", typeof(MaxLengthRouteConstraint) },
{ "length", typeof(LengthRouteConstraint) },

// Min/Max value constraints
{ "min", typeof(MinRouteConstraint) },
{ "max", typeof(MaxRouteConstraint) },
{ "range", typeof(RangeRouteConstraint) },

// Regex-based constraints
{ "alpha", typeof(AlphaRouteConstraint) },
{ "regex", typeof(RegexRouteConstraint) }

这篇关于DefaultInlineContraintResolver错误的WebAPI 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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