Question

I've build a RESTful web service using NancyFX which I'm now trying to POST to from a separate domain. Of course when I do that, I see a failed OPTIONS message in the console because this is a Cross Site POST and I need to ensure that Nancy responds correctly to the OPTIONS message being sent by the browser. However, when I define a route in my Nancy module:

this.Options["/options/"] = _ => this.OptionsRequest();

private dynamic OptionsRequest()
{
         return this.Response.AsJson(Request)
               .WithHeader("Access-Control-Allow-Origin", "*")
               .WithHeader("Access-Control-Allow-Methods", "POST")
               .WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type");
}

The code never gets hit. I can set a breakpoint on the OptionsRequest() method in debugger and see that the code is never getting hit. However I can issue an OPTIONS request in postman, and the server returns a response (interestingly, it seems to return a response from all URIs, not just the /options/ route I've defined).

Is there a default Nancy OPTIONS behaviour I have to override in order to specify routes for OPTIONS, or is this something to do with the service being hosted in the Visual Studio Development Web Server (Casini)? I've tried everything I can think of and I'm still stumped as to why I can't define behaviour for this particular verb.

Was it helpful?

Solution

Turns out this was a bug in Nancy v0.17.1 (see https://github.com/NancyFx/Nancy/pull/1093). Upgrading to 0.18.0 fixed the issue and allowed my OPTIONS route to work correctly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top