Tuesday, 15 May 2012

angularjs - The requested resource does not support http method 'OPTIONS'.? -



angularjs - The requested resource does not support http method 'OPTIONS'.? -

i making next request asp.net web api set method angular.js client:

var org = { orgid: 111, name: 'testing testing' }; $http.put("http://localhost:54822/api/data/putorganisation/1/", org).then(function(status) { console.log("success put"); homecoming status.data; });

however getting next errormsg (in fiddler):

{"message":"the requested resource not back upwards http method 'options'."}

this part of asp.net web api web.config file:

<system.webserver> <httpprotocol> <customheaders> <add name="access-control-allow-origin" value="*" /> <add name="access-control-allow-headers" value="content-type,x-xsrf-token,x-requested-with" /> <add name="access-control-allow-methods" value="get, post, put, delete, options" /> </customheaders> </httpprotocol> <validation validateintegratedmodeconfiguration="false" /> <handlers> <remove name="extensionlessurlhandler-integrated-4.0" /> <remove name="optionsverbhandler" /> <remove name="traceverbhandler" /> <add name="extensionlessurlhandler-integrated-4.0" path="*." verb="*" type="system.web.handlers.transferrequesthandler" precondition="integratedmode,runtimeversionv4.0" /> <remove name="webdav" /> </handlers> <modules runallmanagedmodulesforallrequests="true"> <remove name="webdavmodule" /> </modules> </system.webserver>

data controller web api:

public httpresponsemessage options() { var response = new httpresponsemessage(); response.statuscode = httpstatuscode.ok; homecoming response; } public httpresponsemessage putorganisation(int id, [frombody]organisation org) { var opstatus = _repository.updateorganisation(org); if (opstatus.status) { homecoming request.createresponse<organisation>(httpstatuscode.accepted, org); } homecoming request.createerrorresponse(httpstatuscode.notmodified, opstatus.exceptionmessage); }

this question: why errormsg ( see above) when create same request in fiddler ( works) in angularclient (does not work)??

this cors problem. i'd first read it create sure understand , why important. , guess server configuration not correct.

unfortunately, don't know much .net, cors tutorial .net describes should quite clearly.

it looks missing enablecors annotation. looks need add together [enablecors("*", "*", "*")] controller. explicit handling of options not necessary. of course, in producition, don't want utilize wildcards cors handling. should more specific, fine testing.

angularjs rest asp.net-web-api cors

No comments:

Post a Comment