0

Hi I have developed one small web api crud application and hosted in IIS server. I am able to do the all the operations. I hosted in the server 192.168.0.213:7777 and it is working fine. These services i am trying to access from another application through angularjs as below.

 this.deleteSubscriber = function (user_id) {
        var url = 'http://192.168.0.213:7777/api/User_Creation/' + user_id;
        return $http.delete(url).then(function (response) {
            return response.data;
        });
    }

Whenever i tried to delete user i am getting error message as below.

Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
XMLHttpRequest cannot load http://192.168.0.213:7777/api/User_Creation/37. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:26079' is therefore not allowed access. The response had HTTP status code 405.

May i know why I am getting this issue? Do i need to make any changes in the iis or in my application? Thank you...

7
  • Thank you for your message. May i know which header? I am not sure about this because i am new to web api. Commented Jan 13, 2017 at 6:34
  • enable-cors.org/server_iis6.html Commented Jan 13, 2017 at 6:34
  • Is your angular app and web service running on separate ip? Commented Jan 13, 2017 at 6:38
  • Yes.. Running in seperate ip. Commented Jan 13, 2017 at 6:40
  • @mitesh if i right click on site i do not get properties tab. I get options like explore,edit permissions,add application,add virtual directory and many more. Commented Jan 13, 2017 at 6:42

1 Answer 1

4

You can enable CORS in iis8 by configuring customHeaders

<system.webServer>
  <httpProtocol>
    <customHeaders>
      <add name="Access-Control-Allow-Origin" value="*"/>
      <add name="Access-Control-Allow-Headers" value="Content-Type"/>
      <add name="Access-Control-Allow-Methods" value="POST,GET,DELETE"/>
    </customHeaders>
  </httpProtocol>
</system.webServer>

Can also be configured at code level - Enabling Cross-Origin Requests in ASP.NET Web API 2

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. if i give in controller level such as [EnableCors(origins: "mywebclient.azurewebsites.net", headers: "", methods: "")] then in methods should i mention PUT,DELETE,GET?
In web.config i found <remove name="OPTIONSVerbHandler" /> Is it fine if this piece of code is there?
i edited config file and added piece of code above controller level still no luck.
For example in controller above delete i have [AcceptVerbs("DELETE")] do i need to change anything here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.