Adding Custom JavaScript and HTTP Headers?

Topics: Core, Customizing Orchard, General, Installing Orchard
Jun 30, 2015 at 12:47 PM
Hi. I have a basic Orchard deployment running, this is my first go-around with the product and it is very slick. Thanks to all for putting it together!

My deployed site now needs two things, and I will need to reproduce this customization across future Orchard depoyments:
  1. Add 2 custom HTTP Headers to the deployed site. The headers will have the same key across every site, but different values. Ideally I would like to pull the values from a config file or database.
  2. Let external custom JavaScript execute in the header or footer of the page and in certain widgets. The script is to log analytics so I am trying to understand how to dynamically add a reference to the external script easily.
Thanks for all ideas!
Jun 30, 2015 at 4:29 PM
1 - The purpose of adding 2 headers is a bit unclear to me, but you could write a custom action filter:
public class CustomHeadersFilter : FilterProvider, IActionFilter
    private readonly IOrchardServices _orchardServices;

    public CustomHeadersFilter(IOrchardServices orchardServices)
        this._orchardServices = orchardServices;

    void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
        // Append your headers here using filterContext.HttpContext and
        // this._orchardServices to get header values from the admin
        // (you also have to write the admin component that will let you manage the values)

    void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext) { }
2 - You can use absolute URLs in the script registration in your view.cshtml / layout.cshtml / document.cshtml, like you would do with any other script:
@ {
    Script.Include("<absolute url of your script>").AtFoot();
I don't know if there is any way to do this without writing any code.