【问题标题】:Web API 405 Method Not Allowed In Remote远程不允许使用 Web API 405 方法
【发布时间】:2014-08-19 11:19:28
【问题描述】:

以下是我的行动之一:

public IHttpActionResult PutUnit(int id, Unit unit)
{
    if (!ModelState.IsValid)
        return BadRequest(ModelState);

    if (id != unit.UnitId)
        return BadRequest();

    db.Entry(unit).State = EntityState.Modified;

    try
    {
        db.SaveChanges();
    }
    catch (DbUpdateConcurrencyException)
    {
        if (!UnitExists(id))
        {
            return NotFound();
        }
        else
        {
            throw;
        }
    }

    return StatusCode(HttpStatusCode.NoContent);
}

以下是我得到的回复:

Date: Tue, 19 Aug 2014 10:30:31 GMT
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
Allow: GET, HEAD, OPTIONS, TRACE
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Content-Type: text/html
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Content-Length: 1293

我的控制器的所有操作在本地都可以正常工作,但是一旦我在远程服务器上部署了相同的项目。我无法仅访问控制器的 PUTDELETE 操作,而是出现 405/Method Not Allowed 错误。 web.configwebapiconfig.cs 是相同的并且使用默认结构。请问有什么建议吗?

【问题讨论】:

    标签: c# http asp.net-web-api asp.net-web-api2


    【解决方案1】:
    猜你喜欢
    • 2013-03-21
    • 1970-01-01
    • 2014-06-11
    • 2014-08-21
    • 2016-04-18
    • 2018-02-04
    • 2016-03-23
    • 1970-01-01
    • 2018-05-27
    相关资源
    最近更新 更多