0
votes

I need a way how to add an custom html header in Umbraco. Ideally the value of this custom field can be modified by having an extra textbox in the page editor for that page (Similar to page title box).

Is this possible to do?

1

1 Answers

0
votes

Do you mean you want to add HTTP headers via code-behind?

Assuming you've already created your textstring property on the document type in question, you have to be able to access the property from code-behind or inline code and then add the HTTP header, also from code-behind.

The quickest way to add C# code to the template is to do inline code, e.g.

    <script runat="server">
        protected void Page_Init(object sender, EventArgs e)
        {

        }
    </script>

Alternatively, you can add code-behind files to your template (more info)

Now that you can run server code, you can access the doc type property and create the HTML header.

    umbraco.NodeFactory.Node currentNode = umbraco.NodeFactory.Node.GetCurrent();
    umbraco.interfaces.IProperty httpHeader = currentNode.GetProperty("httpHeaderAlias");

And of course, finally add the HTTP header

    Response.AddHeader("HeaderName", httpHeader.Value);

All together now, add this to your template (masterpage aspx):

    <script runat="server">
        protected void Page_Init(object sender, EventArgs e)
        {
            umbraco.NodeFactory.Node currentNode = umbraco.NodeFactory.Node.GetCurrent();
            umbraco.interfaces.IProperty httpHeader = currentNode.GetProperty("httpHeaderAlias");

            Response.AddHeader("HeaderName", httpHeader.Value);
        }
    </script>

(Note: Code is for Umbraco 4.7)