Table of Contents

Interface ILinkService

Namespace
ToSic.Sxc.Services
Assembly
ToSic.Sxc.dll

Helpers to create links to

  • Pages
  • APIs
  • Images

As well as create base-tag links (important for SPAs)

You will never create this yourself, as get this automatically in Razor or WebAPIs on an object called Link.

[PublicApi]
public interface ILinkService : ICanDebug
Inherited Members

Remarks

History

  • Created ca. v2 as ToSic.Sxc.Web.ILinkHelper
  • Moved to this new Services.ILinkService in v13.05. The previous name will continue to work, but newer features will be missing on that interface.

Methods

Base()

A base url for the current page, for use in html-base tags

string Base()

Returns

string

Image(string, object, object, NoParamOrder, IField, object, object, object, string, string, string, object, string, object)

Generate an Image-Resizing link base on presets or custom parameters.
It will also ensure that the final url is safe, so it will encode umlauts, spaces etc.

Note that you can basically just use presets, or set every parameter manually.

  • All params are optional.
  • Some combinations are not valid - like setting a factor and a width doesn't make sense and will throw an error
  • Most parameters if set to 0 will cause a reset so that this aspect is not in the URL
string Image(string url = null, object settings = null, object factor = null, NoParamOrder noParamOrder = default, IField field = null, object width = null, object height = null, object quality = null, string resizeMode = null, string scaleMode = null, string format = null, object aspectRatio = null, string type = null, object parameters = null)

Parameters

url string

The image url. Use an empty string if you want to just get the params for re-use.

settings object
  • A standardized Image-Settings object like Settings.Images.Content - see https://go.2sxc.org/settings
  • Or a dynamic object containing settings properties (this can also be a merged custom + standard settings)
  • Or a specially prepared IResizeSettings object containing all settings. If this is provided, only factor will still be respected, all other settings like width on this command will be ignored.
factor object

A multiplier, usually used to create urls which resize to a part of the default content-size. Eg. 0.5.

noParamOrder NoParamOrder

see Convention: Named Parameters

field IField

WIP v13.04 - not final yet

width object

Optional width parameter. Usually takes the default from the settings.

height object

Optional height parameter. Usually takes the default from the settings.

quality object

Optional quality parameter. Usually takes the default from the settings.

resizeMode string

Optional resize-mode, like crop or max. Usually takes the default from the settings.

scaleMode string

Optional scale-mode to allow up-scaling images like up or both. Usually takes the default from the settings.

format string

Optional file format like jpg or png

aspectRatio object

Aspect Ratio width/height, only relevant if a width is supplied. Can't be used together with height. Usually takes default from the settings or is ignored.

type string

Optional type changes how the link is generated. Possible values are:

  • null / not specified / empty = return link as is generated
  • "full" return link with protocol and domain. If that was missing before, it will add current protocol/domain if possible, but not on relative ./ or ../ links
  • "//" return link with //domain. If that was missing before, will add current domain if possible, but not on relative ./ or ../ links
parameters object
  • the parameters either as id=47&name=daniel (Dnn also supports /id/47/name/daniel)
  • in 2sxc 12.05+ it can also be an IParameters

Returns

string

Remarks

Usually a factor is applied to create a link which is possibly 50% of the content-width or similar. In these cases the height is not applied but the aspectRatio is used, which usually comes from settings if any were provided.

History

  • New in 2sxc 12.03
  • type added ca. v12.08
  • Option to use IResizeSettings added in v13.03
  • factor originally didn't influence width/height if provided here, updated it v13.03 to influence that as well
  • field being added in 13.04, not ready yet

To(NoParamOrder, int?, string, object, string, string)

returns a link to the current page with parameters resolved in a way that DNN wants it

string To(NoParamOrder noParamOrder = default, int? pageId = null, string api = null, object parameters = null, string type = null, string language = null)

Parameters

noParamOrder NoParamOrder

see Convention: Named Parameters

pageId int?

optional page ID (TabId) - if not supplied, will use current page

api string

optional api url "api/name/method?id=something"

parameters object
  • the parameters either as id=47&name=daniel (Dnn also supports /id/47/name/daniel)
  • in 2sxc 12.05+ it can also be an IParameters
type string

Optional type changes how the link is generated. Possible values are:

  • null / not specified / empty = return link as is generated
  • "full" return link with protocol and domain. If that was missing before, it will add current protocol/domain if possible, but not on relative ./ or ../ links
  • "//" return link with //domain. If that was missing before, will add current domain if possible, but not on relative ./ or ../ links
language string
  • If not set, null or empty "" will use the specified pageId (pageIds can be language specific); api would always be the current language
  • If set to "current" will adjust pageId to use the language of the current language. API will be as before, as it was already current
  • future (not implemented yet) "primary" would link to primary language
  • future (not implemented yet) "en" or "en-us" would link to that specific language (page and API)

Returns

string

Remarks

History

  • v12 added the api parameter for liking APIs of the current app
  • In v12.05 the type of parameters was changed from string to object, to allow IParameters as well
  • In v13.02 introduced language with "current"