Hi I am developing web api2 project. I hosted application in server 192.168.0.213 and I am trying to access the methods as below.
this.getSubs = function () {
var url = 'http://192.168.0.213:7777/api/User_Creation/';
return $http.get(url).then(function (response) {
return response.data;
});
}
Above function returns the data with no issues. For example my below methods with verbs such as PUT,DELETE and POST not working.
this.saveSubscriber = function (sub) {
return $http({
method: 'post',
data: JSON.stringify(sub),
url: 'http://192.168.0.213:7777/api/User_Creation/',
contentType: "application/json"
});
}
I tried many ways still did not worked any methods. Currently i have below code in web.config file.
<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,PUT,DELETE" />
</customHeaders>
Also i have below line of code in webapiconfig.cs file.
private static void EnableCrossSiteRequests(HttpConfiguration config)
{
var cors = new EnableCorsAttribute(
origins: "*",
headers: "*",
methods: "*");
config.EnableCors(cors);
}
Also i have below line of code in controller. Still does not working anything.
[EnableCors(origins: "http://192.168.0.213:7777", headers: "*", methods: "*")]
Also i commented . I tried all the ways only GET verb is working fine. My insert update delete operations are not working. May I know where i am doing things wrong? May i get some help on this as i tried my best still no luck.. Thank you all.