ANGULARJS: "XMLHttpRequest cannot load http://localhost:62259/Service1.svc/getAllUsers. Invalid HTTP status code 405" -
so, situation:
- i developing web app angularjs (client-side) , c# (server-side);
- i have web services running well, no problems (gelallusers, getorderdetails, etc etc);
after implement authentication code, web services stop working. here errors messages:
- options http://localhost:62259/service1.svc/getallusers
- xmlhttprequest cannot load http://localhost:62259/service1.svc/getallusers. invalid http status code 405
i realized problem due every code lines "$http.defaults.headers.common.authorization = ..."
after search, know may need allows authorization header.
but what? , how?and where?
i found solution, , works article in codeproject. novice in web developing, here detailed procedure had follow in order perform successfully:
understand why problem exists , needed enable cors in wcf:
- read article in http://www.codeproject.com/articles/845474/enabling-cors-in-wcf
- believe me, it's worth it. wouldn't explain better;
- read article in http://www.codeproject.com/articles/845474/enabling-cors-in-wcf
as using visual studio develop wcf web services, in order create file global.asax, had to: * in solution explorer, right-click in project name -> add -> new item... * in left menu, web -> general , select global application class * write code:
protected void application_beginrequest(object sender, eventargs e)
{
httpcontext.current.response.addheader("access-control-allow-origin", "http://localhost"); if (httpcontext.current.request.httpmethod == "options") { httpcontext.current.response.addheader("access-control-allow-methods", "post, put, delete"); httpcontext.current.response.addheader("access-control-allow-headers", "content-type, accept, authorization"); httpcontext.current.response.addheader("access-control-max-age", "1728000"); httpcontext.current.response.end(); }
}
note that, in case, needed add 'authorization' in
httpcontext.current.response.addheader("access-control-allow-headers", "content-type, accept, authorization");
delete similar stuff might have in web.config or else have conflict due redundant data.
i thing said everything.
Comments
Post a Comment