Razor Guide to HtmlPage v3.0
Properties To Change Title, Description, Keywords
HtmlPage.Description
(get/set) - Read/Write the page description. v1.1HtmlPage.Keywords
(get/set) - Read/Write the page keywords. v1.1HtmlPage.Title
(get/set) - Read/Write the page title. v1.1
Commands to Add Headers
HtmlPage.AddMeta(name, content)
- Adds a meta-tag with this name and content to the header. v1.1HtmlPage.AddJsonLd(...)
create a JSON-LD (linked data) header see also google guideline and Schema.org. v1.1HtmlPage.AddToJsonLd(string)
- uses a string, which should already be a valid jsonHtmlPage.AddToJsonLd(object)
- will JSON-serialize whatever you pass into it. For now, we recommend usingDictionary<string, object>
to prepare the data you want to add.
HtmlPage.AddOpenGraph(property, content)
add an open-graph tag to the header for facebook, twitter and co. v1.1HtmlPage.AddToHead(string)
- Add anything to the<head>
section of the page. The string should usually contain a meta, link or script tag. v1.1HtmlPage.AddIcon(path)
add an icon (favicon) to the page v2.1...AddIcon(path, rel: string, size: int, type: string)
- all optional parameters to specify things likerel
: the rel-text, default is 'icon'. common terms are also 'shortcut icon' or 'apple-touch-iconsize
: will be used in size='#x#' tag; only relevant if you want to provide multiple separate sizestype
: optional type, if not provided, will be auto-detected from known types or remain empty
HtmlPage.AddIconSet(path)
add a few icon headers to the page according to best practices v2.1...AddIconSet(path, favicon: bool|string, rels: IEnumerable<string>, sizes: IEnumerable<int>)
- all optional parameters to specify things likefavicon
: boolean - auto-add a default favicon tag (or not)favicon
: string - use this url for the favicon tagrels
: list/array of rel-texts (a separate icon tag will be generated for each rel)sizes
: list/array of sizes (a separate icon tag will be generate for each size)
note: if you supplyrels
andsizes
, then all combinations of icon tags will be added
note: you can't specify the type, as each one could be different - the auto-detection will take care of this for you
Performance Optimizations
The commands above are available for comfortable use. Internally, each command finds the page object and manipulates it. If you would like to optimize the code a bit, the GetPage()
command gives you an object with the same features, but will run a few percent faster. So you can also do this:
var p = HtmlPage.GetPage();
p.Title = "...";
p.Keywords = "...;