3

Hi I am developing services in web api2 vs2015. Initially i had cors issue i fixed and http verbs like get,delete,put,post working fine in mozilla and internet explorer. I am getting errors in google chrome for put and delete request. I am not able to do put and delete in google chrome. This is my request and response values in chrome.

Request URL:http://192.168.0.213:8041/User_Creation/1019
Request Method:OPTIONS
Status Code:400 Bad Request
Remote Address:192.168.0.213:8041
**Response Headers**
view source
Cache-Control:no-cache
Content-Length:58
Content-Type:application/json; charset=utf-8
Date:Mon, 16 Jan 2017 10:07:04 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/8.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
**Request Headers**
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Access-Control-Request-Headers:
Access-Control-Request-Method:DELETE
Connection:keep-alive
Host:192.168.0.213:8041
Origin:http://192.168.0.213:8040
Referer:http://192.168.0.213:8040/usercreation/Index
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36

I have below line of code in web.config

 <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Methods" value="POST, PUT, DELETE, GET, OPTIONS" />
        <add name="Access-Control-Allow-Headers" value="content-Type, accept, origin, X-Requested-With, Authorization, name" />
        <add name="Access-Control-Allow-Credentials" value="true" />
      </customHeaders>
      </httpProtocol>

Am i missing anything here?

I am sending requesting delete http verb and in 3rd line i can see options verb. I am confused here. May i know how can i fix this issue? Thank you for your help.

Niranjan Godbole
  • 2,055
  • 6
  • 32
  • 72
  • Looks like a `OPTIONS` verb being used first. Please see http://stackoverflow.com/questions/21783079/ajax-in-chrome-sending-options-instead-of-get-post-put-delete or http://stackoverflow.com/questions/29954037/how-to-disable-options-request. – Petre T Jan 16 '17 at 10:58
  • Thanks yes may be that was the problem. I have below error Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.0.213:8040' is therefore not allowed access. The response had HTTP status code 400. I did not find any solution in the link. – Niranjan Godbole Jan 16 '17 at 11:18
  • Ok, have you tried http://stackoverflow.com/questions/27504256/mvc-web-api-no-access-control-allow-origin-header-is-present-on-the-requested ? – Petre T Jan 16 '17 at 11:30
  • Yes. Still only delete not working. Rest all working – Niranjan Godbole Jan 16 '17 at 11:43
  • Very interesting thing is after page load if i click on delete i will get error. If i click on delete after update my delete also works. do not know what is this? – Niranjan Godbole Jan 16 '17 at 12:12

0 Answers0