.net Web API放回404

.net Web API放回404,.net,asp.net-web-api,.net,Asp.net Web Api,我用angular js请求一个put-to-web API,但得到了404响应。不过,get和post的工作非常好。原因可能是什么。我目瞪口呆,人们都在谈论webdev,我几乎什么都试过了,仍然是愚蠢的404 请求者和API都在同一个域上,http://locathost/api和http://localhost/app 服务器端代码 // PUT: api/Projects/5 [ResponseType(typeof(void))] public async Task&

我用angular js请求一个put-to-web API,但得到了404响应。不过,get和post的工作非常好。原因可能是什么。我目瞪口呆,人们都在谈论webdev,我几乎什么都试过了,仍然是愚蠢的404

请求者和API都在同一个域上,
http://locathost/api
http://localhost/app

服务器端代码

  // PUT: api/Projects/5
    [ResponseType(typeof(void))]
    public async Task<IHttpActionResult> PutProject(int id, Project project)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        if (id != project.Id)
        {
            return BadRequest();
        }

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

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

        return StatusCode(HttpStatusCode.NoContent);
    }
}))

angularjs控制器调用它

  Api.update({ id: 9}, {id:9,projectName: 'test', number: 'test', dateTime: 'test', inspector: 'test', neighborhood: 'test', field1: 'test', field2: 'test' });
我得到的错误是什么

 Remote Address:127.0.0.1:8888
Request URL:http://localhost/api/projects/9
Request Method:PUT
Status Code:404 Not Found
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Content-Length:136
Content-Type:application/json;charset=UTF-8
Host:localhost
Origin:http://localhost
Proxy-Connection:keep-alive
Referer:http://localhost/App/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36
Request Payloadview source
{id: 9, projectName: "test", number: "test", dateTime: "test", inspector: "test", neighborhood: "test",…}
dateTime: "test"
field1: "test"
field2: "test"
id: 9
inspector: "test"
neighborhood: "test"
number: "test"
projectName: "test"
Response Headersview parsed
HTTP/1.1 404 Not Found
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Sat, 04 Apr 2015 05:03:54 GMT
Content-Length: 5270

看看这两篇文章

如果此POST不可访问,则需要检查IIS处理程序映射,以确保模块允许的所有谓词:

  • 无扩展UrlHandler-ISAPI-4.0_32位
  • 无扩展UrlHandler-ISAPI-4.0_64位
  • ExtensionlessUrlHandler-Integrated-4.0

您可能需要在您的服务url(IIS运行的端口)中指定get and post正在工作的端口号,您的意思是在angular服务上使用8888吗?我试过了,但没用。默认端口为80,也没有任何帮助。是否尝试过:
 Remote Address:127.0.0.1:8888
Request URL:http://localhost/api/projects/9
Request Method:PUT
Status Code:404 Not Found
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Content-Length:136
Content-Type:application/json;charset=UTF-8
Host:localhost
Origin:http://localhost
Proxy-Connection:keep-alive
Referer:http://localhost/App/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36
Request Payloadview source
{id: 9, projectName: "test", number: "test", dateTime: "test", inspector: "test", neighborhood: "test",…}
dateTime: "test"
field1: "test"
field2: "test"
id: 9
inspector: "test"
neighborhood: "test"
number: "test"
projectName: "test"
Response Headersview parsed
HTTP/1.1 404 Not Found
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Sat, 04 Apr 2015 05:03:54 GMT
Content-Length: 5270