ANGULARJS: "XMLHttpRequest cannot load http://localhost:62259/Service1.svc/getAllUsers. Invalid HTTP status code 405" -


so, situation:

  1. i developing web app angularjs (client-side) , c# (server-side);
  2. i have web services running well, no problems (gelallusers, getorderdetails, etc etc);
  3. after implement authentication code, web services stop working. here errors messages:

  4. i realized problem due every code lines "$http.defaults.headers.common.authorization = ..."

  5. 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:

  1. understand why problem exists , needed enable cors in wcf:

  2. 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(); } 

}

  1. note that, in case, needed add 'authorization' in

    httpcontext.current.response.addheader("access-control-allow-headers", "content-type, accept, authorization");

  2. delete similar stuff might have in web.config or else have conflict due redundant data.

i thing said everything.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -