gpt4 book ai didi

c# - Asp.net Mvc 5 中的 HttpPut?

转载 作者:行者123 更新时间:2023-11-30 16:12:15 26 4
gpt4 key购买 nike

我试图在我的 Controller 中使用“PUT”

public class HomeController : Controller
{
[HttpPut]
public ContentResult Test()
{
return Content("hi");
}
}

但是我无法访问它。我以为这是我的代码,但在尝试 fiddler 并得到相同的错误 (404) 之后。

我想还有别的事情发生了。我只使用 iis express 和 mvc 5。

在我从未使用过 HttpPut 但最近一直在使用 webapi 之前,这就是我尝试在 mvc 5 Controller 中使用它的原因,但我不确定在这种情况下它是否会给我带来任何东西(尤其是需要额外的设置,因为它看起来像是需要的)

enter image description here

发布请求有效

enter image description here

最佳答案

另一种可能性是更新 ExtensionlessUrlHandler-Integrated-4.0。

<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>

可以在以下位置找到此解决方案: Attribute routing with http PUT method constraint

关于c# - Asp.net Mvc 5 中的 HttpPut?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23230670/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com