ASP.NET MVC PUT DELETE 404 C# mvc delete put 失败

发布时间 2023-07-05 17:29:22作者: 我是韩一
  • 对于使用 Url 路由 访问页面的 ASP.NET 应用程序,IIS可能会显示404,403之类的错误代码,而且排除了代码问题(本地运行正常),那么就可以加下面这句话:

    <system.webServer>
        <modules>
          <remove name="UrlRoutingModule-4.0" />
          <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
        </modules>
    </system.webServer>
    Web config

    原因:Url 路由是由 UrlRoutingModule 这个模块来处理的。在某些 IIS 版本中,并不会将所有请求交给 UrlRoutingModule 处理,所以,我们可以在 Web.config 中进行以上设置。

     

  • 下面这句话也可以奏效,但不建议使用, 因为性能会浪费, 还有一些静态文件的请求可能会被要求验证 (比如图片是可以含有 & 符号的, 如果设置了这个, 就会被验证成 invalid 了)

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
    Web config

     

  • WebConfig中添加此代码也可以解决问题-->请查看此链接说明

        <system.webServer>
            <validation validateIntegratedModeConfiguration="false" />
            <modules runAllManagedModulesForAllRequests="true">
                <remove name="WebDAVModule" />
            </modules>
            <handlers>
                <remove name="WebDAV" />
            </handlers>
        </system.webServer>
    Web config

     

  • 本文章为借阅文:借鉴路径