加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 405消息,Web Api不允许的方法

发布时间:2020-12-16 00:35:02 所属栏目:asp.Net 来源:网络整理
导读:我在API控制器上有以下内容: public void UpdateClient(Client client) { try { if (ModelState.IsValid) { db.Entry(client).State = EntityState.Modified; db.SaveChanges(); } } catch { throw new HttpResponseException(new HttpResponseMessage(Http
我在API控制器上有以下内容:
public void UpdateClient(Client client)
    {
        try
        {
            if (ModelState.IsValid)
            {
                db.Entry(client).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
        catch
        {
            throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
        }
    }

并在页面上的以下内容:

$.ajax({
            url: "api/client/UpdateClient",type: "PUT",contentType: 'json',data: ko.toJSON(model.selectedClient()),success: function (result) {
                getClients();
                $("#loader").hide();
            },failure: function (result) {
                alert(result.d);
                $("#loader").hide();
            },error: function (XMLHttpRequest,textStatus,errorThrown) {
                alert("An error occurred,please try again.");
                $("#loader").hide();
            }
        });

但是这会给出错误405方法不允许,任何人都可以看到我可能出错了吗?为了参考,api的url可以,因为我使用相同的api控制器来做其他的功能。

此外,selectedClient()是通过WebApi接收的客户端对象,所以应该完全匹配PUT再次。

解决方法

如果您使用IIS7并安装了WebDav,请尝试将其删除。
我只是用PUT动词得到相同的错误,解决了这个问题

更新:您可以在这里阅读WebDav:http://www.iis.net/learn/get-started/whats-new-in-iis-7/what39s-new-for-webdav-and-iis-7

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读