使用'。'在使用属性路由的Web Api中出现404错误

时间:2015-05-08 11:08:10

标签: asp.net-web-api routes asp.net-web-api2 asp.net-web-api-routing attributerouting

我正在使用路由属性尝试通过url将字符串发送到我的网络Api。 我将路线定义为

LATERAL JOIN

我期待一个字符串值为searchText。它似乎工作正常,但如果有'',我会收到错误。在我的参数。 对于前者

[Route("Search/{searchText}")]

但是

http://localhost/api/Person/Search/me is working fine, 

在我的浏览器中抛出了404错误。

'。'字符ir使用传统路由正常工作

http://localhost/api/Person/Search/me.me

我收到的错误只是属性路由的情况。 我一直关注所有引用的属性路由这篇文章 - http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2
如何使用属性路由发送'。'字符作为字符串的一部分?

1 个答案:

答案 0 :(得分:1)

尝试将以下内容添加到<system.WebServer><handlers>...</handlers></system.WebServer>部分的Web.config中:

<add name="ApiURIs-ISAPI-Integrated-4.0" path="/Search/*" type="System.Web.Handlers.TransferRequestHandler" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" preCondition="integratedMode,runtimeVersionv4.0" />

线程我曾经解决过同样的问题:[1]:Dots in URL causes 404 with ASP.NET mvc and IIS

编辑:如果您需要为多条路线执行此操作,您可能必须为路径执行/*/*