Last Updated: February 25, 2016
·
1.657K
· yesilfasulye

Access-Control-Allow-Origin Error

Problem: Trying to get jSON data from different domain/projects.

**Error:** XMLHttpRequest cannot load (myurl). Origin (myurl2) is not allowed by Access-Control-Allow-Origin.

Solution :
Add below code to global.asax file in your .NET project which you're trying to get data from...

protected void Application_BeginRequest(object sender, EventArgs e){
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
}