The Content module contains functions to add headers at the Content level without needing to resort to the Context, for example:

1
2
3
4
let baseSitelet =
    Sitelet.Infer <| fun ctx action ->
        Content.Text("example page")
        |> Content.WithHeader "Pragma" "no-cache"

To generalize it to the Sitelet level, you can do something like this:

1
2
3
4
5
6
7
8
module Sitelet =

    let MapContent (f: Async<Content<'T>> -> Async<Content<'T>>) (s: Sitelet<'T>) =
        { s with Controller = { Handle = s.Controller.Handle >> async.Return >> f >> Content.FromAsync } }

let mySitelet =
    baseSitelet
    |> Sitelet.MapContent (Content.WithHeader "Pragma" "no-cache")
By on 9/13/2016 5:15 AM ()

Thanks, it works nicely. Even better with Content.WithHeaders

1
2
3
4
5
6
7
8
9
10
let noCacheHeaders = 
    [ 
        ("Cache-Control", "no-cache, no-store, must-revalidate");
        ("Pragma", "no-cache");
        ("Expires", "0")
    ] |> Seq.map (fun (a,b) -> Http.Header.Custom a b)

let mySitelet =
    baseSitelet
    |> Sitelet.MapContent (Content.WithHeaders noCacheHeaders)
By on 9/14/2016 1:48 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper