Interface ILinkService
Helper on Kit.Link to create links to pages, APIs and images.
[PublicApi]
public interface ILinkService : ICanDebug
- Inherited Members
Remarks
It is usually also available as a Link object in every Razor and WebApi file.
This helps 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.
History
- Created ca. v2 as
ToSic.Sxc.Web.ILinkHelper - Moved to this new
Services.ILinkServicein 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
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
urlstringThe image url. Use an empty string if you want to just get the params for re-use.
settingsobject- A settings name such as "Content", "Lightbox" etc. (new 17.06)
- A standardized Image-Settings object like Settings.Images.Content - see https://go.2sxc.org/settings
- An anonymous objects with properties such as
width,height,quality,resizeMode,scaleMode,format,aspectRatioetc. likenew { width = 100, height = 100 }(new v19.03.03) - 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
factorwill still be respected, all other settings likewidthon this command will be ignored.
factorobjectA multiplier, usually used to create urls which resize to a part of the default content-size. Like 0.5.
noParamOrderNoParamOrderfieldIFieldWIP v13.04 - not final yet
widthobjectOptional width parameter. Usually takes the default from the
settings.heightobjectOptional height parameter. Usually takes the default from the
settings.qualityobjectOptional quality parameter. Usually takes the default from the
settings.resizeModestringOptional resize-mode, like
cropormax. Usually takes the default from thesettings.scaleModestringOptional scale-mode to allow up-scaling images like
uporboth. Usually takes the default from thesettings.formatstringOptional file format like
jpgorpngaspectRatioobjectAspect Ratio width/height, only relevant if a
widthis supplied. Can't be used together with height. Usually takes default from thesettingsor is ignored.typestringOptional 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
parametersobject- 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
- the parameters either as
Returns
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
factororiginally didn't influence width/height if provided here, updated it v13.03 to influence that as wellfieldbeing added in 13.04, not ready yetsettingsenhanced to also support simple anonymous objects in v19.03.03
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
noParamOrderNoParamOrderpageIdint?optional page ID (TabId) - if not supplied, will use current page
apistringoptional api url "api/name/method?id=something"
parametersobject- 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
- the parameters either as
typestringOptional 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
languagestring- If not set,
nullor 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 alreadycurrent - 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)
- If not set,
Returns
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"