Web API delete and put not working when hosted on

2019-08-27 07:23发布

My concern is that my web-api project that returns JSON works, very well locally, but when hosted on shared hosting

I already added this

<modules runAllManagedModulesForAllRequests="true"> <remove name="WebDAVModule"/> </modules>

I also checked this http://geekswithblogs.net/michelotti/archive/2011/05/28/resolve-404-in-iis-express-for-put-and-delete-verbs.aspx

Checked the setting mentioned in this article as well and it was all there.

DELETE and PUT - http://api.antheminfotech.net/api/employees/23 - 500 Error

I have tired a lot of things, I am bit new to web-api so maybe I am missing somthing... or do i need a VPS hosting to have required access....

BTW I am using enitiy framework and creating a autogenerated controllers for this, based on EF models.

 Function PutEmpDetail(ByVal id As Integer, ByVal empdetail As EmpDetail) As HttpResponseMessage
    If Not ModelState.IsValid Then
        Return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)
    End If

    If Not id = empdetail.Id Then
        Return Request.CreateResponse(HttpStatusCode.BadRequest)
    End If

    db.Entry(empdetail).State = EntityState.Modified

    Try
        db.SaveChanges()
    Catch ex As DbUpdateConcurrencyException
        Return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)
    End Try

    Return Request.CreateResponse(HttpStatusCode.OK)
End Function

 Function DeleteEmpDetail(ByVal id As Integer) As HttpResponseMessage
    Dim empdetail As EmpDetail = db.EmpDetails.Find(id)
    If IsNothing(empdetail) Then
        Return Request.CreateResponse(HttpStatusCode.NotFound)
    End If

    db.EmpDetails.Remove(empdetail)

    Try
        db.SaveChanges()
    Catch ex As DbUpdateConcurrencyException
        Return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)
    End Try

    Return Request.CreateResponse(HttpStatusCode.OK, empdetail)
End Function

2条回答
一纸荒年 Trace。
2楼-- · 2019-08-27 07:34

Typically on shared hosting these extra (and yes, they are extra) verbs are not enabled by default. System Administrators are loathe to add extras if 99.99% of the customer base doesn't need it enabled.

Consult with your host if they have it enabled. Likely they don't and, also likely, they may refuse to enable them. If so, ask them about alternatives, otherwise migrate to a different host.

查看更多
Deceive 欺骗
3楼-- · 2019-08-27 07:53

It seems that the probelm lied with the shared hosting, they where not able to bypass security and give the correct access.. I moved the API to a VPS and It worked seemlessly there.

查看更多
登录 后发表回答