I must be missing something incredibly easy. I'm writing a NancyFx app using Xamarin Studio. I want to use the PUT and DELETE HTTP methods in my module, but when I issue a PUT or DELETE request, I get back 405 Method Not Allowed
and I see Allow: GET, POST
in the HTTP response header.
My app is running under xsp4 in Xamarin Studio on OSX. Most of the solutions I've seen to this problem are only relevant when running under IIS.
How do I enable PUT and DELETE in xsp4/Mono/Nancy? I don't believe Nancy is the problem. I'm pretty sure this is confined to the xsp4 server on Mono. Am I missing something in my web.config file (posted below)?
The DELETE handler in my Nancy module looks like this:
Delete["/api/family/{id}"] = _ =>
{
int rows = 0;
using (IDbConnection con = dbFactory.Open())
rows = con.Execute("DELETE FROM Family WHERE Id=?", new { Id = _.id });
return Response.AsJson(rows, HttpStatusCode.OK);
};
My web.config file is very simple. It pretty much just enables Nancy on all paths and verbs, like so:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<httpHandlers>
<add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
</httpHandlers>
<compilation>
<assemblies>
<add assembly="Mono.Data.Sqlite, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
<add assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add assembly="System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<httpErrors existingResponse="PassThrough" />
<handlers>
<add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
</handlers>
</system.webServer>
</configuration>
Here is the HTTP conversation from curl:
> PUT /api/family HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost:8080
> Accept: */*
> Content-Type: application/json
> Content-Length: 262
>
* upload completely sent off: 262 out of 262 bytes
* HTTP 1.0, assume close after body
< HTTP/1.0 405 Method Not Allowed
< Date: Sun, 27 Jul 2014 21:37:46 GMT
< Server: Mono.WebServer2/0.4.0.0 Unix
< Allow: GET, POST
< X-AspNet-Version: 4.0.30319
< Content-Length: 0
< Cache-Control: private
< Content-Type: text/html
< Keep-Alive: timeout=15, max=100
* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive
<
* Connection #0 to host localhost left intact