Thursday 15 September 2011

asp.net mvc - OPTIONS and then POST executing action twice -


When I do $ http.post for a web API from my client on a separate project, both Firebug and Chrome are an option Method and then a POST method

Problem
Both of the requests actually execute my API action if I am restricted to posting, the option fails and Post never happens. CORS is in my corner and webpage.

My app These lines are in JS:

  $ httpProvider.defaults.useXDomain = true; Remove $ HttpProvider.defaults.headers.com ['X-Requested-With'];   

My API call:

  $ scope.add = function () {var role = {name: 'admin'}; $ Http.post ('http: // localhost: 7514 / roll / add', role) success (work) {alert ('rollerscountryr.ed');}) error (function (message) {warnings ('expelled Gone rollers controller.ed ');}); };   

webpi web.config

  & lt; System.webServer & gt; ... & lt !! - Added for cos handling, delete when using a dedicated cours handler or system. WEB.cors dll - & gt; & Lt; HttpProtocol & gt; & Lt; CustomHeaders & gt; & Lt; Add name = "access-control-permission-origin" value = "*" /> & Lt; Add name = "access-control-permission-header" value = "origin, with requested-type, accept content type," /> & Lt; / CustomHeaders & gt; & Lt; / HttpProtocol & gt; & Lt; /system.webServer>    

If you use the nightly consoles package, the message handler to the option request that Does not execute the action, but still sends the appropriate response title. For more information and how to use night packages, you should see this blog post about the CORS Knightley package.

Be sure to select "prelease" from the drop down.

No comments:

Post a Comment