Web应用程序2中的DefaultInlineConstraintResolver错误 [英] DefaultInlineConstraintResolver Error in WebAPI 2

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

问题描述

我正在使用Web API 2,当我使用本地方框上的IIS 7.5向我的API方法发送POST时,我收到以下错误。

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 Express在Visual Studio中运行我的API项目并成功对我的登录API进行POST,但是当我尝试向另一个API调用发出GET请求时,我得到约束解析器错误。

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 Express,我得到的结果与我现有的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.

推荐答案

错误意味着路线中的某个地方,你指定了类似

The error means that somewhere in a Route, you specified something like

[Route("SomeRoute/{someparameter:string}")]

不需要string,因为如果没有指定其他内容,它是假定的类型。

"string" is not needed as it is the assumed type if nothing else is specified.

如错误所示,Web API附带的 DefaultInlineConstraintResolver 没有名为字符串的内联约束。默认支持的是:

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

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

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