Hello,
Is there a way to enable CORS on DNN. I have few angular apps that could use DNN for Authentication/Authorisation but I cant seem to make it work.
I tried setting it in web.cofig via customHeaders but that did not work.
Is there away to enable CORS on DNN (9.3 in my case)?
Regards,
Alex
The short answer is yes, there is a way to enable CORS. However, it is really a loaded question. And, it is typically not a good idea to enable CORS anyway, but rather make sure the proper security is in place for API calls. That said, here are some ideas for you.
If you are on IIS7, you can merge this with your web.config:
For IIS6: 1) Open Internet Information Service (IIS) Manager 2) Right click the site you want to enable CORS for and go to Properties 3) Change to the HTTP Headers tab 4) In the Custom HTTP headers section, click Add 5) Enter Access-Control-Allow-Origin as the header name 6) Enter * as the header value 7) Click Ok twice
Lastly...you may want to try this. In each action method which requires CORS access, add the Access-Control-Allow-Origin header:
var response = this.Request.CreateResponse(HttpStatusCode.OK, new MyResponse { Id = 10 }); response.Headers.Add("Access-Control-Allow-Origin", "*"); return response;
To add on to David's caution, using Access-Control-Allow-Origin: * disables any protections that CORS should provide. Rather, you should use that header to indicate the specific origin that you are expecting. If there are multiple origins that you need to support, you'll need to set the origin dynamically, which would be similar to David's last example.
Access-Control-Allow-Origin: *
response.Headers.Add("Access-Control-Allow-Origin", "https://another.website.example.com");
These Forums are dedicated to the discussion of DNN Platform.
For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:
Awesome! Simply post in the forums using the link below and we'll get you started.