[英]WEB API PUT method is not working and getting HTTP/1.1 405 Method Not Allowed
Hi I am not understanding how to fix this can any one please let me know why my put method is not getting executed. 嗨,我不明白如何解决这个问题,请让我知道为什么我的put方法没有得到执行。 I get error
我得到错误
HTTP/1.1 405 Method Not Allowed
不允许使用HTTP / 1.1 405方法
in my PUT method. 在我的PUT方法中。 Is there any way to fix using ROUTE attribute to debug my PUT method.
有没有什么办法可以使用ROUTE属性来调试我的PUT方法。
public class UserProfessionController : ApiController
{
//[Route("")]
public IHttpActionResult Get()
{
return Ok();
}
[HttpPut]
public HttpResponseMessage UpdateUserProfession([FromUri]string categoryCode)
{
try
{
int userId = 1;
if (String.IsNullOrWhiteSpace(categoryCode))
{
var specialitiesRepository = new UserRepository();
if(specialitiesRepository.UpdateUserProfession(userId, categoryCode) > 0)
{
return Request.CreateResponse(HttpStatusCode.Created);
}
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Invalid Input Data");
}
else
{
throw new Exception("Category Code-" + categoryCode + "For the User " + userId + " is not valid");
}
}
catch (Exception ex)
{
var msg = new HttpResponseMessage(HttpStatusCode.BadRequest)
{
Content = new StringContent(ex.Message),
ReasonPhrase = "Invalid Input Data"
};
throw new HttpResponseException(msg);
}
}
}
in web.config system.webServer: 在web.config system.webServer中:
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/>
</modules>
After struggling with this issue - tried the changes to config and IIS regarding removing WebDAV with no success, I tried the following and the issue was resolved. 解决此问题后-尝试对配置和IIS进行有关删除WebDAV的更改均未成功,我尝试了以下操作,此问题已解决。
Remove WebDAV publishing from the IIS install from control panel/program and features - select "turn windows features on/off" 从控制面板/程序和功能的IIS安装中删除WebDAV发布-选择“打开/关闭Windows功能”
Found this solution at the link below. 在下面的链接中找到了此解决方案。
https://ignas.me/tech/405-method-not-allowed-iis/ https://ignas.me/tech/405-method-not-allowed-iis/
This fixed the issue on both Windows 10 and 7. 这已在Windows 10和7上解决了该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.