My website is running fine. Basically I am having some html pages that calls a webapi to get the results and bind the chart. The api only sends the json data and rest is done on html page in script tag.
Now I have to integrate some of my website pages into another website so I have created the html pages but when I run them I am getting Error - 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
The mvc code:
[HttpGet, Route("DevD"), OutputCache(Duration = 5, VaryByHeader = "Origin")]
public ActionResult GetDevD(double value1)
{
return Json(_devD, JsonRequestBehavior.AllowGet);
}
private static object _devD;
private static object GetDevD()
{
dynamic trend = Trend;
return new
{
trend?.day,
volume = new abc(GetLastTick("JZ"))
};
}
In global.ascx
protected void Application_BeginRequest()
{
var origin = Request.Headers["Origin"];
if (!string.IsNullOrWhiteSpace(origin) && (origin.EndsWith("abc.com") || origin.EndsWith("www.watrade.net")))
{
Response.Headers.Add("Access-Control-Allow-Origin", origin);
Response.Headers.Add("Access-Control-Allow-Headers", "accept, content-type");
}
if (Request.HttpMethod != "OPTIONS") return;
Response.End();
}
I don't want to use any plugin. What changes should I made in this code so that it runs in my website also and can be integrated in another website also.