这似乎比我擅长的更深入IIS!因此,我有一个非常适合GET和POST的Web API控制器。第一个屏幕截图显示了对GET的处理。一切都很棒,我得到了回应。
但是随后我提出了一个PUT请求,一切都崩溃了。它似乎遍历ManagedPipelineHandler,然后陷入DefaultDocumentModule,并失败,并出现405。
没有安装WebDAV,无论如何我都尝试在web.config级别将其删除。处理程序被覆盖以支持PUT。
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" />
</handlers>
Despite this the request is failing to be handled by ASP.NET and I'm looking for some ideas on debugging? Here is the action method that fails, the PUT and one that works, a GET.
public class ProductsController : ApiController
{
[HttpPut]
[Route("api/products")]
public AddProductResponse AddProduct(AddProductRequest request)
{
return new AddProductResponse();
}
[HttpGet]
[Route("api/products/manufacturers")]
public ManufacturersResponse GetProductManufacturers()
{
var productService = new ProductService();
var manufacturers = productService.GetManufacturers();
return new ManufacturersResponse { Manufacturers = manufacturers.OrderBy(m => m.BusinessName) };
}
}
Seems I missed the hand off early in the request lifecycle.
FREB seems to show the GENERAL_SHILD_REQUEST_START for the PUT, not sure why the managed pipeline is creating that extra child request that ultimately falls to the DefaultDocumentModule which can't handle a PUT.
Looked at your scenario (thanks for sharing you repro project), and the issue is that the projected placed the webapi in a /api folder inside the project.
Specifically there was also /api/products, so when the path /api/products was hit for the http put, IIS seen it as a directory browsing request, and refused to serve a PUT verb on it.
解决方案:重命名api文件夹,通常不要尝试在调用REST API的位置正确映射文件夹。在部署中这不是问题,但是在本地Web应用程序上,该文件夹在那里,并且IIS首先处理它。
另一个解决方案(尽管不建议使用)是使用
<modules runAllManagedModulesForAllRequests="true" />
这将使ASP.NET抢先攻破IIS,但是不建议您这样做,只是为了解决类似这样的小问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句