November Happy Hour will be moved to Thursday December 5th.

Class UrlSegment

This class determines behavior for URL Segments, intended to be used by the UrlRewriter functionality.

Inheritance
System.Object
UrlSegment
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Web
Assembly: EPiServer.dll
Version: 9.12.2
Syntax
[ServiceConfiguration]
public class UrlSegment

Constructors

UrlSegment(IContentRepository, IContentProviderManager, SiteDefinitionResolver, SiteDefinitionRepository)

Initializes a new instance of the UrlSegment class.

Declaration
public UrlSegment(IContentRepository contentRepository, IContentProviderManager contentProviderManager, SiteDefinitionResolver siteDefinitionResolver, SiteDefinitionRepository siteDefinitionRepository)
Parameters
Type Name Description
IContentRepository contentRepository
IContentProviderManager contentProviderManager
SiteDefinitionResolver siteDefinitionResolver
SiteDefinitionRepository siteDefinitionRepository

The Site Definition repository

Fields

InvalidSegmentNames

A regular expression that defines invalid URL segments based on various device definitions etc that exists in Windows.

Declaration
public static string InvalidSegmentNames
Field Value
Type Description
System.String

Properties

SimpleAddressRouter

Gets or sets the simple address router.

Declaration
public SimpleAddressSegmentRouter SimpleAddressRouter { get; set; }
Property Value
Type Description
SimpleAddressSegmentRouter

The simple address router.

Remarks

This is mainly exposed for testing purposes.

URLCharacterMap

A Char to Char mapping used by the default autogenerated URL Segment used in Friendly URL. This should be a hashtable mapping char-to-replacement-char.

Declaration
public static Hashtable URLCharacterMap { get; set; }
Property Value
Type Description
System.Collections.Hashtable
Remarks

Defaults to a list of common ISO-8859-1 characters with a suggested replacement

UseLowerCaseSegments

Gets or sets a value indicating whether url segments should be created in lowercase.

Declaration
public static bool UseLowerCaseSegments { get; set; }
Property Value
Type Description
System.Boolean

true if url segment is created in lowercase; otherwise, false.

Remarks

Default value is true.

Methods

CreateUrlSegment(IContent)

Creates a URL segment (siebling unique) for a content

Declaration
public static string CreateUrlSegment(IContent content)
Parameters
Type Name Description
IContent content

The content.

Returns
Type Description
System.String

Unique url segment

FindCollidingReference(ContentReference, ContentReference, String, String)

Finds a colliding reference which is a different content item that has same url segment on the same langauge.

Declaration
public virtual ContentReference FindCollidingReference(ContentReference contentLink, ContentReference parentLink, string urlSegment, string language)
Parameters
Type Name Description
ContentReference contentLink

The content link.

ContentReference parentLink

The parent link.

System.String urlSegment

The URL segment.

System.String language

The language.

Returns
Type Description
ContentReference

GetContentBySegment(ContentReference, String)

Gets the content by segment.

Declaration
public virtual ContentReference GetContentBySegment(ContentReference parentLink, string urlSegment)
Parameters
Type Name Description
ContentReference parentLink

The parent reference

System.String urlSegment

The URL segment.

Returns
Type Description
ContentReference

GetContentBySegment(ContentReference, String, Boolean, IContentRepository)

Gets the content by segment.

Declaration
[Obsolete("Use instance method GetContentBySegment instead")]
public static ContentReference GetContentBySegment(ContentReference parent, string urlSegment, bool exactLanguage, IContentRepository contentRepository)
Parameters
Type Name Description
ContentReference parent

The parent.

System.String urlSegment

The URL segment.

System.Boolean exactLanguage

True if we require an exact language match. False may return any match if no exact language is found.

IContentRepository contentRepository

The content repository.

Returns
Type Description
ContentReference

The content or EmptyReference. If no exact language match is found, return any match if there is one.

Remarks

This implementation depends on fast reference-based IContent objects.

GetPageBySegment(PageReference, String, String, Boolean)

Gets the page by segment.

Declaration
[Obsolete("Use instance method GetContentBySegment instead")]
public static PageReference GetPageBySegment(PageReference parent, string urlSegment, string languageBranch, bool exactLanguage)
Parameters
Type Name Description
PageReference parent

The parent.

System.String urlSegment

The URL segment.

System.String languageBranch

The language we want (or null/empty if we don't care)

System.Boolean exactLanguage

True if we require an exact language match. False may return any match if no exact language is found.

Returns
Type Description
PageReference

The page or EmptyReference. If no exact language match is found, return any match if there is one.

Remarks

This implementation depends on fast reference-based read-only PageDataCollections and PageData objects.

GetUniqueURLSegment(IContent)

Gets a friendly URL segment based on the content name and possibly a sequence number. URL Segments may collide within a specific content, i.e. different languageBranches can have the same URL Segment, but sibling nodes may not.

Declaration
public static string GetUniqueURLSegment(IContent content)
Parameters
Type Name Description
IContent content

The content to create the segment for

Returns
Type Description
System.String

A valid URL segment for the content

Remarks

There is potential for race here, since we don't save the segment once we've built it. The caller should probably lock for the duration.

GetURLCharacterMap()

Gets the URL character map.

Declaration
public static Hashtable GetURLCharacterMap()
Returns
Type Description
System.Collections.Hashtable

An initialized map

GetUrlFriendlySegment(String)

Replace illegal chars with suggested replacements

Declaration
public static string GetUrlFriendlySegment(string segment)
Parameters
Type Name Description
System.String segment

The segment.

Returns
Type Description
System.String

ValidateEventHandler(Object, PageValidateEventArgs)

Called to validate the URLSegement. Will update PageURLSegment with valid value if it's not set.

Declaration
[Obsolete("This has been obsoleted by the generic content validation system.")]
public static void ValidateEventHandler(object sender, PageValidateEventArgs e)
Parameters
Type Name Description
System.Object sender

The sender.

PageValidateEventArgs e

The PageValidateEventArgs instance containing the event data.

Remarks

This is only relevant to do if the page is writeable.

VerifyContentHasSegment(ContentReference, String)

Verifies the content has segment.

Declaration
public virtual ContentReference VerifyContentHasSegment(ContentReference contentLink, string urlSegment)
Parameters
Type Name Description
ContentReference contentLink

The content link.

System.String urlSegment

The URL segment.

Returns
Type Description
ContentReference

VerifyContentHasSegment(ContentReference, String, IContentRepository)

Verifies that the content has the given URL segment.

Declaration
[Obsolete("Use instance method VerifyContentHasSegment instead")]
public static ContentReference VerifyContentHasSegment(ContentReference contentLink, string urlSegment, IContentRepository contentRepository)
Parameters
Type Name Description
ContentReference contentLink

The content link.

System.String urlSegment

The URL segment.

IContentRepository contentRepository

The page repository.

Returns
Type Description
ContentReference

VerifyPageHasSegment(PageReference, String, String)

Verifies that the page has the given URL segment.

Declaration
[Obsolete("Use instance method VerifyContentHasSegment instead")]
public static PageReference VerifyPageHasSegment(PageReference pageLink, string urlSegment, string languageBranch)
Parameters
Type Name Description
PageReference pageLink

The page link.

System.String urlSegment

The URL segment.

System.String languageBranch

The language branch.

Returns
Type Description
PageReference

The PageReference for the page if we have a matcn, null otherwise.

Events

CreatedUrlSegment

Occurs when an url segment has been created

Declaration
public static event EventHandler<UrlSegmentEventArgs> CreatedUrlSegment
Event Type
Type Description
System.EventHandler<UrlSegmentEventArgs>

CreatingUrlSegment

Occurs when an url segment is to be created

Declaration
public static event EventHandler<UrlSegmentEventArgs> CreatingUrlSegment
Event Type
Type Description
System.EventHandler<UrlSegmentEventArgs>

Extension Methods