【发布时间】:2017-01-24 21:27:45
【问题描述】:
如果创建一个与控制器具有相同名称/路由的根级文件夹,IIS 似乎会尝试路由到该文件夹,而不是参考 WebAPI 2 路由。
示例:
ProjectA
|- Controllers/
|-- ExamplesController.cs
|- Examples/
ExamplesController
[RoutePrefix("examples")]
public class ExamplesController : ApiController
{
[HttpGet]
[Route("")]
public async Task<IHttpActionResult> Get()
{
// code
}
}
预期是命中控制器,但 IIS 似乎尝试浏览文件夹。
例如:http://localhost:123/examples
尝试的解决方案:
我尝试过使用 IIS 处理程序,看看是否可以删除所有其他处理程序,但这没有帮助
Web.config
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<clear/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
【问题讨论】:
标签: asp.net iis asp.net-web-api2