Take the community feedback survey now.

Ravindra S. Rathore
Aug 2, 2019
  11065
(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
Optimizely SaaS CMS Developer Certification

I have recently passed the Optimizely SaaS CMS Developer Certification. Sharing my experience, hope this helps. https://academy.optimizely.com/stud...

Madhu | Sep 22, 2025 |

Get last run of a scheduled job in Optimizely CMS

Learn how to get the last execution time of a scheduled job in Optimizely CMS.

Tomas Hensrud Gulla | Sep 20, 2025 |

Replacement Language Settings

Hi, Today I would like to share my learnings about the Replacement Language option in Optimizely CMS and Commerce. Replacement language is used to...

Harinarayanan | Sep 20, 2025

Locating Blocks Stored in “For This Page” When Retiring Block Models

When maintaining a long-lived Optimizely CMS site, you’ll eventually need to deprecate block types. The usual approach is to remove the block class...

Pär Wissmark | Sep 19, 2025 |

World Login is Moving to Opti ID

Starting Wednesday, September 24th, (at 2:00 PM EST) world.optimizely.com will require Opti ID for all logins. This change brings World in line wit...

Satata Satez | Sep 19, 2025

Helping Opal Build LLMS.TXT Content

In my previous blog, Opal Tools Support Comes to Stott Robots Handler v6 , I shared the news about new Opal Tools being built directly into the Sto...

Mark Stott | Sep 19, 2025