2014-11-22 49 views
0

嗨,我不理解如何解决这个问题,任何人都可以让我知道为什么我的put方法没有得到执行。我得到错误WEB API PUT方法无法正常工作并且获取HTTP/1.1 405方法不允许

HTTP/1.1 405方法在我的PUT方法不被允许

。有什么方法可以使用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); 
     } 


    } 
} 
+0

状态405意味着web服务器不支持所使用的方法,你的情况PUT。该错误与您的代码没有任何关系。你使用什么网络服务器? – 2014-11-22 22:11:21

回答

0
在web.config中system.webServer

<modules runAllManagedModulesForAllRequests="true"> 
    <remove name="WebDAVModule"/> 
</modules> 
+0

谢谢fr anser – 2014-11-22 22:31:37

+0

您也可以从IIS中删除WebDAV,而不是更改web.config文件 – IdoT 2014-11-23 11:22:12

0

这个问题挣扎之后 - 尝试更改配置和IIS就没有成功删除WebDAV,我尝试以下和问题是解决。从IIS

删除WebDAV发布从控制面板/程序和功能安装 - 选择“打开窗户,开/关”

实测值在下面的链接该溶液中。

https://ignas.me/tech/405-method-not-allowed-iis/

这解决了该问题在Windows 10和7