1、为什么会出现Method not found
说明地址:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status/405
这里顺带也说一下跨域的问题,详情看下一官方文档:https://docs.microsoft.com/zh-cn/aspnet/core/security/cors?view=aspnetcore-2.2

2、解决办法
由于描述了 GET、HEAD 或 POST浏览器是可以跳过预检请求的,接口中涉及到了PUT、DELETE时就会出现Method not found
这时候由于netcore默认使用的是AspNetCoreModuleV2模块,需要使用AspNetCoreModule模块,打开web.config文件移除掉WebDAVModule模块
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers accessPolicy="Read, Script">
<remove name="aspNetCore" />
<remove name="WebDAV" />
<!-- I removed the following handlers too, but these
can probably be ignored for most installations -->
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" requireAccess="Script" />
</handlers>
本文探讨了MethodNotFound错误的根源,特别是在涉及到PUT、DELETE等HTTP方法时,并提供了详细的解决方案,包括修改web.config文件来避免预检请求,以及如何正确配置AspNetCoreModule模块。
853

被折叠的 条评论
为什么被折叠?



