Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Martin Rud 162 posts 586 karma points c-trib
    Mar 17, 2022 @ 14:00
    Martin Rud

    How to add header with "Access-Control-Allow-Origin: *" in Umbraco 9?


    I have some JavaScript that needs to have access to external json. How do I configure my site to allow this?

  • Ambert van Unen 158 posts 766 karma points c-trib
    Mar 17, 2022 @ 14:37
    Ambert van Unen

    I've added a little bit of middleware so I can add custom headers.

    for example: startup.cs

           app.UseUmbraco() ......


     public class CustomHeaders{
     private readonly RequestDelegate _next;
        public CustomHeaders(RequestDelegate next)
            _next = next;
        public async Task InvokeAsync(HttpContext context)
            context.Response.Headers.Add("X-Frame-Options", "sameorigin");
            context.Response.Headers.Add("X-Xss-Protection", "1; mode=block");
            context.Response.Headers.Add("X-Content-Type-Options", "nosniff");
            await _next(context);

    You could add your Access-Control-Allow-Origin in a similar way.

  • Carlos Mosqueda 239 posts 428 karma points
    Mar 17, 2022 @ 17:25
    Carlos Mosqueda

    That is a very nice dolution Ambert.

    This actually answered a bit of my questions. Is this compiled into the "projectName.dll" ?

  • Ambert van Unen 158 posts 766 karma points c-trib
    Mar 17, 2022 @ 19:18
    Ambert van Unen

    Yes it is :-)

Please Sign in or register to post replies

Write your reply to: