GetPartialVirtualPath Method

Assembly: EPiServer (in EPiServer.dll) Version: 10.10.4.0 (10.10.4.0)

Gets a partial virtual path for a content item during routing.

Syntax:

C#
PartialRouteData GetPartialVirtualPath(
	TRoutedData content,
	string language,
	RouteValueDictionary routeValues,
	RequestContext requestContext
)

Parameters:

content

Type: TRoutedData

The content to generate a virtual path for.

language

Type: System.String

The language to generate the url for.

routeValues

Type: System.Web.Routing.RouteValueDictionary

The route values.

requestContext

Type: System.Web.Routing.RequestContext

The request context.

Remarks

During construction of an URL for a IContent instance there is a check if any IPartialRouter instance is registered for the type of the content. If so the IPartialRouter instance is called to generate a partial path of the URL.

An example would be the generation of an url like http://sitehost/aPage/extendedPart/extendedContent/. If there is an IPartialRouter registered for the type matching extendedContent that instance will be called to generate a partial virtual path. In the example the implementation could return PartialVirtualPath as 'extendedPart/extendedContent/' and BasePathRoot set as a reference to the page that matches the url http://sitehost/aPage/.

Examples

The below example is a partial router that generates partial URLs like 'Sport/A%20News/'. In the example the URL part 'http://sitehost/News/' is to a page of type NewsContainer the reference to that page is given by field _newsContainer. The part 'Sport/A%20News' is handled by the partial router.

CopyC#
public PartialRouteData GetPartialVirtualPath(NewsContent content, string language, RouteValueDictionary routeValues, RequestContext requestContext)
{
    if (ContentReference.IsNullOrEmpty(_newsContainer))
    {
        throw new InvalidOperationException("property NewsContainer must be set on start page");
    }
    return new PartialRouteData()
    {
        BasePathRoot = _newsContainer,
        PartialVirtualPath = String.Format("{0}/{1}/",
            content.Category.ToString(),
            HttpUtility.UrlPathEncode(content.Name))
    };
}

See Also