Is there an equivalent in Giraffe to Url.Content("~/")?

Viewed 50

In ASP.NET MVC, I used occasional calls such as Url.Content("~/Some folder/") to get the full path of different URLs.

Is there anything similar in Giraffe?

The following code comes from the default app I created with the template:

let layout (content: XmlNode list) =
    html [] [
        head [] [
            title []  [ encodedText "TestAccountsManager" ]
            link [ _rel  "stylesheet"
                   _type "text/css"
                   _href "/main.css" ]
        ]
        body [] content
    ]

Is /main.css relative to the root of the application? Or is it relative to the server name? In ASP.NET MVC, I would use something like ~/css/main.css, let's say. If the app is deployed under http://example/someapp/ or http://example/ I know this would work in both cases.

1 Answers

In the case of the default Giraffe template, where static resources get put in the WebRoot folder, it seems to work if you use:

_href "./main.css"

This allows for deploying the web application at the root of the host, or as a "folder" one level below the root.

If you are putting the static resources in a folder below the WebRoot, then resources would go in the folder:

WebRoot\Subfolder

(e.g. WebRoot\css), and the href attribute would need to be changed to:

_href "./Subfolder/main.css

(e.g. _href "./css/main.css")

Related