net core在IIS上部署出现Method not found

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>
posted @ 2020-03-05 16:03  Jonny-Xhl  阅读(657)  评论(0编辑  收藏  举报