I'm new to orchard cms. I've created a custom module with api controller. The only problem is I can't get the data from api when I use cross domain
2
votes
2 Answers
2
votes
I had added the below lines of code on Global.asax of Orchard.Web and it works
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("X-Frame-Options");
HttpContext.Current.Response.Headers.Add("Access-Control-Allow-Origin", "*");
}
1
votes
There is one trick that you don't need to break the original orchard source. You catch and response the preflight request with expected config.
public class ProductsController : ApiController
{
[HttpOptions]
public HttpResponseMessage EnableCors()
{
var response = Request.CreateResponse();
response.Headers.Add("Access-Control-Allow-Origin", "your client");
response.Headers.Add("Access-Control-Allow-Methods", "methods");
response.Headers.Add("Access-Control-Allow-Headers", "content-type");
return response;
}
}