DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

CORS on DNN

 2 Replies
 0 Subscribed to this topic
 40 Subscribed to this forum
Sort:
Author
Messages
New Around Here
Posts: 1
New Around Here

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

Veteran Member
Posts: 360
Veteran Member
Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
MVP
MVP
You're an MVP!

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:

[code]
var response = this.Request.CreateResponse(HttpStatusCode.OK, new MyResponse { Id = 10 });
response.Headers.Add("Access-Control-Allow-Origin", "*");
return response;
[/code]

David Poindexter


Creator:


Advanced Member
Posts: 159
Advanced Member
MVP
MVP
You're an MVP!

To add on to David's caution, using <code>Access-Control-Allow-Origin: *</code> 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.

<code>response.Headers.Add("Access-Control-Allow-Origin", "https://another.website.example.com");</code>

These Forums are for the discussion of the open source CMS DNN platform and ecosystem.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
  2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
  3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  5. No Flaming or Trolling.
  6. No Profanity, Racism, or Prejudice.
  7. Site Moderators have the final word on approving / removing a thread or post or comment.
  8. English language posting only, please.

Would you like to help us?

Awesome! Simply post in the forums using the link below and we'll get you started.

Get Involved