Ravindra S. Rathore
Aug 2, 2019
  11986
(10 votes)

Retrieving absolute url of current page on any page or block

Hi,

If you've ever tried to get the full URL of a current page then this blog post may come handy. So basically you will need VirtualPathArguments, That will have ContextMode facility to enable it based on our needs. For instance Default mode, Edit mode, Preview mode and obviously an Undefined mode if the Context has not been defined.

And then obviously the "Uri" method with the "SiteDefinition.Current.SiteUrl".

This is a small blog post that covers the absolute/full URL of the current page on any block or on a page.

            var routeHelper = ServiceLocator.Current.GetInstance<IPageRouteHelper>();
          
            var pageUrl = UrlResolver.Current.GetUrl(routeHelper.Page.ContentLink,
                ContentLanguage.PreferredCulture.Name,
                new VirtualPathArguments { ContextMode = EPiServer.Web.ContextMode.Default });

            var absoluteurl = new Uri(SiteDefinition.Current.SiteUrl, pageUrl);

However, I've created an instance of PageRouteHelper just for a demo purpose but you should always inject your dependencies and get them resolved with IOC container like StructureMap which Episerver recommends.

Thanks

Ravindra

Aug 02, 2019

Comments

Please login to comment.
Latest blogs
CMS 12 - Optimizely DAM Integration 2.2.0

What's New in Optimizely DAM Integration 2.2.0 Version 2.2.0 of the Optimizely DAM (CMP) integration for CMS 12 is a pretty big release. Many of th...

Robert Svallin | Apr 12, 2026

CMS 13: The New Core Element of Your AI-First Optimizely Platform

CMS 13 is out and already brings solid AI-first foundations. With impressive features already shipped and an exciting roadmap ahead, this is the...

Michał Mitas | Apr 11, 2026 |

Deploying to Linux in SaaS (Configured) Commerce

With Optimizely SaaS (Configured) Commere now suporting net8.0 extensions dll, you will need to make a small tweak to how you distribute you...

Mark Hall | Apr 10, 2026 |

Optimizely CMS 13 and the Alloy demo site

The Alloy demo site now runs on Optimizely CMS 13. Here’s a quick guide to getting it up and running locally.

Tomas Hensrud Gulla | Apr 10, 2026 |