PathToUrlMapper.TryTransformUrl Method

Namespace
Kampute.DocToolkit.Routing
Assembly
  • Kampute.DocToolkit.dll

Definition

Attempts to transform a URL string to its corresponding replacement URL.
public bool TryTransformUrl(string urlString, [NotNullWhen(true)] out Uri replacementUrl)

Parameters

urlString string
The URL string to find a replacement for.
replacementUrl Uri
When this method returns, contains the replacement URL if found; otherwise, null.

Returns

bool
true if a replacement URL was found; otherwise, false.

Remarks

This method attempts to find a corresponding replacement URL for the given URL string based on the defined mappings. It handles several common URL variations to maximize the chance of finding a match:
  • It attempts to match both URL-encoded and decoded path variations
  • It tries matching paths both with and without file extensions
When a match is found, the method preserves fragment identifier of the original URL and combines its query parameters with any existing query parameters in the mapped URL. This ensures that the full context of the original URL is retained in the replacement URL.