AngularJS $http.put 在发布时返回 405

问题描述 投票:0回答:1

我有一个使用 AngularJS 的 ASP.NET 项目。我正在使用

$http.put
更新数据库中的某个记录,并且我需要
.then
稍后执行某些操作。 我有一个 IIS 服务器。 当我使用 Visual Studio 在本地测试代码时,它工作正常。但是,一旦我将内容移至 IIS,我就会收到 405 状态。

我使用的电话是这样的:

$http.put(req, oB).then(function(r) {  DoSomething(oB.Id); })

对象 oB 在调用此请求的函数中定义。

它在控制器中调用的函数是:

[HttpPut("{id}")]
public async Task<ActionResult> PutOb(int id, Object ob)
{
    if (id != ob.Id)
    {
        return BadRequest();
    }
    var oldOb= _context.Object.Where(x => x.Id == ob.Id).FirstOrDefault();
    oldOb.Name = ob.Name;
    _context.Entry(oldOb).State = EntityState.Modified;


    try
    {
        await _context.SaveChangesAsync();
    }
    catch (DbUpdateConcurrencyException)
    {
        if (!obExisit(id))
        {
            return NotFound();
        }
        else
        {
            throw;
        }
    }

    return NoContent();
}

我什至尝试只调用

put
而不使用
.then
,但我仍然遇到同样的错误。

更新:激活 FailedRequestTracing 会在日志中显示此信息。 enter image description here

asp.net angularjs http iis
1个回答
0
投票

经过多次尝试,我按照此处的帖子解决了该问题。但是,我必须不包括以下部分:

<handlers>
    <remove name="WebDAV" />
</handlers>

添加此部分后,我收到了 500 错误。

© www.soinside.com 2019 - 2024. All rights reserved.