I am getting No 'Access-Control-Allow-Origin' header is present on the requested resource error when azure web application is requesting azure web API resource, but locally it is working fine, I am getting the above error after deployment when I am accessing the azure website.
Below is the code:
angular js service:
function industrysearchservice(appConfig, $q) {
var dsIndustry;
var schemaIndustry = {
data: function (response) {
return response.value;
},
total: function (response) {
return response['@odata.count'];
},
model: {
id: "Industry"
}
};
getIndustries = function (filter) {
var deferred = $q.defer();
var dsFetch = new kendo.data.DataSource({
batch: false,
schema: schemaIndustry,
type: "odata-v4",
serverFiltering: true,
serverSorting: true,
serverPaging: true,
pageSize: 20,
transport: {
read: {
url: appConfig.odataUri + "/PSellerIndustryFilter",
dataType: "json",
data: {
$select: "Industry"
}
}
}
});
if (!angular.isUndefined(filter))
dsFetch._filter = filter;
dsFetch.fetch().then(function () {
dsIndustry = dsFetch;
deferred.resolve(dsIndustry);
});
return deferred.promise;
}
return { getIndustries: getIndustries };
}
controller method:
public class PSellerIndustryFilterController : ODataController
{
PSellerContext db = new PSellerContext();
private bool PSellerIndustryExists(System.Guid key)
{
return db.PSellerIndustryFilters.Any(p => p.Industry == key.ToString());
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
[EnableQuery]
public IQueryable<PSellerIndustryFilter> Get()
{
return db.PSellerIndustryFilters;
}
[EnableQuery]
public SingleResult<PSellerIndustryFilter> Get([FromODataUri] System.Guid key)
{
IQueryable<PSellerIndustryFilter> result = db.PSellerIndustryFilters.Where(p => p.Industry == key.ToString());
return SingleResult.Create(result);
}
}