Bob*_*way 13 iis asp.net-mvc http-put
我正在研究MVC应用程序.在我的原始服务草案中,我在我的一个控制器中使用了这个方法:
[AcceptVerbs(HttpVerbs.Post)]
[ActionName("UpdateRelationship")]
public ActionResult UpdateRelationship(string aParameter)
Run Code Online (Sandbox Code Playgroud)
这很好.在最新版本中,我被要求将其更改为PUT请求,以区别于使用post的类似添加机制.所以我改成了这个:
[AcceptVerbs(HttpVerbs.Put)]
[ActionName("UpdateRelationship")]
public ActionResult UpdateRelationship(string aParameter)
Run Code Online (Sandbox Code Playgroud)
突然之间我的请求得到了404,所有这一切都只是改变了AcceptVerbs.从错误的外观来看,似乎IIS正在尝试将请求路由为标准的webforms页面,而不是使用MVC无扩展URL重写.
谷歌搜索这似乎是一个常见的原因是浏览器不允许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>
Run Code Online (Sandbox Code Playgroud)
那么我错过了什么?
编辑:此代码适用于同事的机器.所以看起来我的本地IIS设置是错误的.仍然无法解释我需要改变的东西 - 任何想法?
干杯,马特
我必须完全删除此博客文章中所述的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,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<modules>
<remove name="WebDAVModule" />
</modules>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
经过多次无果的搜索和涉及 WebDAV 的死胡同后,我在另一个 SO 家族网站上找到了答案:)
https://serverfault.com/questions/93424/how-to-enable-put-and-delete-in-iis7
| 归档时间: |
|
| 查看次数: |
15422 次 |
| 最近记录: |