asp.net-mvc – 在.NET MVC上启用Http PUT请求

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – 在.NET MVC上启用Http PUT请求前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在开发一个MVC应用程序.在我原来的服务草案中,我在我的一个控制器中有这种方法
[AcceptVerbs(HttpVerbs.Post)]
    [ActionName("UpdateRelationship")]
    public ActionResult UpdateRelationship(string aParameter)

而且工作正常.在最新的修订版本中,我被要求将其更改为PUT请求,以将其与使用帖子的类似添加机制区分开来.所以我改为:

[AcceptVerbs(HttpVerbs.Put)]
    [ActionName("UpdateRelationship")]
    public ActionResult UpdateRelationship(string aParameter)

突然间,我根据我的要求得到了404,所有这些都只是改变了AcceptVerbs.从错误的外观看,IIS似乎尝试将请求作为标准Webforms页面进行路由,而不是使用MVC extensionless url重写.

Googling这似乎是一个常见的原因是浏览器不允许PUT请求,但我没有使用浏览器来测试这个 – 我使用的是Fiddler.所以应该没有问题.我也认为正确的设置已经在web.config中:

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
  <remove name="WebDAVModule" />
    </modules>
    <handlers>
        <remove name="UrlRoutingHandler" />
        <remove name="MvcHttpHandler" />
  <remove name="WebDAV" />
        <add name="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler,System.Web.Mvc,Version=2.0.0.0,Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
    </handlers>
    <security>
        <requestFiltering>
            <verbs>
                <add verb="PUT" allowed="true" />
            </verbs>
        </requestFiltering>
    </security>
</system.webServer>

那么我错过了什么?

编辑:此代码适用于同事的机器.所以看起来我的本地IIS设置是错误的.仍然在失去解释什么我需要改变 – 任何想法?

干杯,
马特

解决方法

我不得不在 this blog post完全删除WebDav模块
<configuration>
  <system.webServer>
    <handlers>
      <remove name="WebDAV" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <modules>
      <remove name="WebDAVModule" />
    </modules>
  </system.webServer>
</configuration>
原文链接:https://www.f2er.com/aspnet/246341.html

猜你在找的asp.Net相关文章