0

I request a put to web API with angular js but I get a 404 response. The get and post work great though. what could be the reason. I goggled and people were talking about webdev I tried pretty much everything still the stupid 404.

both the requester and API are on the same domain, http://locathost/api and http://localhost/app

server side code

  // 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 Service

mediaApp.factory('Api', function ($resource) {
var data = $resource('http://localhost/api/projects/:id', {id: '@id'}, {
    update:{
        method:'PUT'
    }
});
return data;

});

angularjs controller calling it

  Api.update({ id: 9}, {id:9,projectName: 'test', number: 'test', dateTime: 'test', inspector: 'test', neighborhood: 'test', field1: 'test', field2: 'test' });

and the the error I get

 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
johnny
  • 2,032
  • 1
  • 25
  • 45
  • you may need to specify port number in your service url (the port that IIS is running on) – Mike Debela Apr 04 '15 at 05:57
  • the get and post is working, do you mean to 8888 on angular service? I tried this but didn't work. the default port is 80 and it doesn't help either. – johnny Apr 04 '15 at 06:04
  • did you try: http://stackoverflow.com/questions/10099270/asp-net-web-api-returns-404-for-put-only-on-some-servers – Khanh TO Apr 04 '15 at 09:20

1 Answers1

0

Take a look at this two posts

In case this posts unreachable, you need to check IIS Handler Mappings to be sure that all verbs allowed for modules:

  • ExtensionlessUrlHandler-ISAPI-4.0_32bit
  • ExtensionlessUrlHandler-ISAPI-4.0_64bit
  • ExtensionlessUrlHandler-Integrated-4.0
bonzaster
  • 313
  • 2
  • 12