• Basics
  • Abyss
  • Web APIs
  • C# & Razor
  • .net API
  • JS & TS API

    Show / Hide Table of Contents

    Interface IPageService

    Make changes to the page - usually from Razor.

    Namespace: ToSic.Sxc.Services
    Assembly: ToSic.Sxc.dll
    Syntax
    [PublicApi]
    public interface IPageService
    Remarks

    History

    • Introduced in v12.02 but on another namespace which still works for compatibility
    • Moved to ToSic.Sxc.Services in v13
    • Added ability to use placeholder [original] in v13.11
    • Most commands were updated to return an empty string in v14.02 so that they could be used as inline razor (previously void)

    Methods

    | Improve this Doc View Source

    Activate(String, Boolean, String[])

    Activate a feature on this page, such as turnOn, 2sxc.JsCore etc. For list of features, see Page Service to Activate Features & WebResources (JS, CSS, etc.).

    Declaration
    string Activate(string noParamOrder = "Params must be named (https://r.2sxc.org/named-params)", bool condition = true, params string[] features)
    Parameters
    Type Name Description
    System.String noParamOrder

    see Convention: Named Parameters

    System.Boolean condition

    Condition to determine if activation should happen

    System.String[] features

    One or more strings containing Page-Feature keys

    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.Activate(...)

    Remarks
    • This overload with condition added in v15.03
    | Improve this Doc View Source

    Activate(String[])

    Activate a feature on this page, such as turnOn, 2sxc.JsCore etc. For list of features, see Page Service to Activate Features & WebResources (JS, CSS, etc.).

    Declaration
    string Activate(params string[] keys)
    Parameters
    Type Name Description
    System.String[] keys

    One or more strings containing Page-Feature keys

    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.Activate(...)

    | Improve this Doc View Source

    AddCsp(String, String[])

    Add a CSP rule where you also specify the name. Best check the CSP Guide.

    For an example, see Coded CSP

    Declaration
    string AddCsp(string name, params string[] values)
    Parameters
    Type Name Description
    System.String name
    System.String[] values
    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.AddCsp(...)

    | Improve this Doc View Source

    AddIcon(String, String, String, Int32, String)

    Add an Icon header tag to the Page.

    Declaration
    string AddIcon(string path, string noParamOrder = "Params must be named (https://r.2sxc.org/named-params)", string rel = "", int size = 0, string type = null)
    Parameters
    Type Name Description
    System.String path

    Path to the image/icon file

    System.String noParamOrder

    see Convention: Named Parameters

    System.String rel

    the rel-text, default is 'icon'. common terms are also 'shortcut icon' or 'apple-touch-icon'

    System.Int32 size

    Will be used in size='#x#' tag; only relevant if you want to provide multiple separate sizes

    System.String type

    An optional type. If not provided, will be auto-detected from known types or remain empty

    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.AddIcon(...)

    | Improve this Doc View Source

    AddIconSet(String, String, Object, IEnumerable<String>, IEnumerable<Int32>)

    Add a set of icons to the page

    Declaration
    string AddIconSet(string path, string noParamOrder = "Params must be named (https://r.2sxc.org/named-params)", object favicon = null, IEnumerable<string> rels = null, IEnumerable<int> sizes = null)
    Parameters
    Type Name Description
    System.String path

    Path to the image/icon file

    System.String noParamOrder

    see Convention: Named Parameters

    System.Object favicon

    path to favicon, default is '/favicon.ico'

    System.Collections.Generic.IEnumerable<System.String> rels
    System.Collections.Generic.IEnumerable<System.Int32> sizes
    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.AddIconSet(...)

    | Improve this Doc View Source

    AddJsonLd(Object)

    Add a JSON-LD header according https://developers.google.com/search/docs/guides/intro-structured-data

    Declaration
    string AddJsonLd(object jsonObject)
    Parameters
    Type Name Description
    System.Object jsonObject

    A object which will be converted to JSON. We recommend using dictionaries to build the object.

    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.AddJsonLd(...)

    | Improve this Doc View Source

    AddJsonLd(String)

    Add a JSON-LD header according https://developers.google.com/search/docs/guides/intro-structured-data

    Declaration
    string AddJsonLd(string jsonString)
    Parameters
    Type Name Description
    System.String jsonString

    A prepared JSON string

    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.AddJsonLd(...)

    | Improve this Doc View Source

    AddMeta(String, String)

    Add a standard meta header tag. You may also want to use AddOpenGraph(String, String) or AddJsonLd(String)

    Declaration
    string AddMeta(string name, string content)
    Parameters
    Type Name Description
    System.String name
    System.String content
    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.AddMeta(...)

    | Improve this Doc View Source

    AddOpenGraph(String, String)

    Add an open-graph header according to http://ogp.me/

    Declaration
    string AddOpenGraph(string property, string content)
    Parameters
    Type Name Description
    System.String property

    Open Graph property name, like title or image:width. 'og:' is automatically prefixed if not included

    System.String content

    value of this property

    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.AddOpenGraph(...)

    | Improve this Doc View Source

    AddToHead(String)

    Add a tag to the header of the page Will simply not do anything if an error occurs, like if the page object doesn't exist

    Declaration
    string AddToHead(string tag)
    Parameters
    Type Name Description
    System.String tag
    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.AddToHead(...)

    | Improve this Doc View Source

    AddToHead(IHtmlTag)

    Add a RazorBlade Tag to the headers of the page Will simply not do anything if an error occurs, like if the page object doesn't exist

    Declaration
    string AddToHead(IHtmlTag tag)
    Parameters
    Type Name Description
    IHtmlTag tag
    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.AddToHead(...)

    | Improve this Doc View Source

    AssetAttributes(String, Boolean, Int32, String, Boolean)

    Add common html attributes to a script or link tag to enable optimizations and automatically whitelist in the Content Security Policy

    Declaration
    IHybridHtmlString AssetAttributes(string noParamOrder = "Params must be named (https://r.2sxc.org/named-params)", bool optimize = true, int priority = 0, string position = null, bool whitelist = true)
    Parameters
    Type Name Description
    System.String noParamOrder

    see Convention: Named Parameters

    System.Boolean optimize

    Activate optimize, default is true

    System.Int32 priority

    Optional priority of optimization. Must be more than 100 to have an effect.

    System.String position

    Optional position of the resource (head, body, bottom)

    System.Boolean whitelist

    Automatically add to CSP-whitelist. This uses a random key to protect against XSS.

    Returns
    Type Description
    IHybridHtmlString

    The asset attributes in a format which will be preserved in HTML

    Remarks

    History: Created in 2sxc 13.10

    | Improve this Doc View Source

    SetBase(String)

    Add a standard base header tag or replace it if one is already provided.

    Declaration
    string SetBase(string url = null)
    Parameters
    Type Name Description
    System.String url

    the optional url for the base tag - if null, will try to default to the real url for the current page

    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.SetBase(...)

    | Improve this Doc View Source

    SetDescription(String, String)

    Set the Page Description. It will either try to replace the placeholder (second parameter) or prefix it to the existing description (unless [original] is given).

    See also the details with placeholder or [original] as explained on SetTitle(String, String)

    Declaration
    string SetDescription(string value, string placeholder = null)
    Parameters
    Type Name Description
    System.String value
    System.String placeholder
    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.SetDescription(...)

    | Improve this Doc View Source

    SetHttpStatus(Int32, String)

    Set the page status code if possible (it will work in DNN, but probably not in Oqtane)

    Declaration
    string SetHttpStatus(int statusCode, string message = null)
    Parameters
    Type Name Description
    System.Int32 statusCode

    An HTTP status code like 404

    System.String message

    Message / Description text (optional) which would be included in the header

    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.SetHttpStatus(...)

    | Improve this Doc View Source

    SetKeywords(String, String)

    Set the Page Keywords. It will either try to replace the placeholder (second parameter) or prefix it to the existing keywords (unless [original] is given).

    See also the details with placeholder or [original] as explained on SetTitle(String, String)

    Declaration
    string SetKeywords(string value, string placeholder = null)
    Parameters
    Type Name Description
    System.String value
    System.String placeholder
    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.SetKeywords(...)

    | Improve this Doc View Source

    SetTitle(String, String)

    Set the Page Title. Behavior:

    • By default it will prefix the new title - SetTitle(&apos;My New Title - &apos;) = My New Title - Blog - 2sxc.org
    • You can also use the new [original] token like SetTitle(&apos;[original] - My New Title&apos;) = Blog - 2sxc.org - My New Title
    • You can add a placeholder to the page-title and tell SetTitle what it is. SetTitle(&apos;My New Title&apos;, &apos;2sxc.org&apos;) =Blog - My New Title`
    Declaration
    string SetTitle(string value, string placeholder = null)
    Parameters
    Type Name Description
    System.String value
    System.String placeholder
    Returns
    Type Description
    System.String

    Empty string, so it can be used on inline razor such as @Kit.Page.SetTitle(...)

    | Improve this Doc View Source

    TurnOn(Object, String, Object, Object)

    Turn on some javascript code when all requirements have been met. Uses turnOn.

    Will automatically activate the feature and set hidden data on the page for the turnOn JS to pick up.

    Declaration
    string TurnOn(object runOrSpecs, string noParamOrder = "Params must be named (https://r.2sxc.org/named-params)", object require = null, object data = null)
    Parameters
    Type Name Description
    System.Object runOrSpecs
    • either a run string like window.myObject.myJs() (must always start with window)
    • or a object containing all the parameters which turnOn requires
    System.String noParamOrder

    see Convention: Named Parameters

    System.Object require

    optional One or more requirements which must be met before the code starts. Can be one or many values and/or functions.

    • a string such as window.myObject or window.myObject.readyToStart()
    • a array of such strings
    System.Object data

    optional any value such as a string, or an object - to pass into the run-command

    Returns
    Type Description
    System.String

    An empty string, just so you can use it directly in Razor like @Kit.Page.TurnOn(&quot;...&quot;)

    Remarks

    New in v15.

    • Improve this Doc
    • View Source
    Back to top Generated by DocFX