I want to get current page url in my razor code.how to retrieve that?

  • what research have you done and what have you tried? Jul 4, 2015 at 16:46
  • I have added HttpContext.Current and Request.Url.ToString() in my razor code but it gives me Null Reference exception.
    – User 45
    Jul 6, 2015 at 10:34

2 Answers 2


The Razor Mediator has excellent documentation, including the info you're looking for: https://code.google.com/p/razor-mediator-4-tridion/downloads/detail?name=RazorMediatorDocumentation_v1.3.3.docx

In your case I think you'll want to use the @Publication.PublicationUrl to get the URL then concatenate the @Page.FileName onto the end of it.

  • Hi Tanner Thanks for the update....but There are some different implementation in my project.Your suggestion @Publication.PublicationUrl will give me the current page URL which is present in Tridion CMS. I want current browser URL in my Razor/TOM.NET code. In my project there are one dynamic page and 100+ components has been indexed to that single page. For each components I don't have particular page.
    – User 45
    Jul 7, 2015 at 9:14

Where and when is your code being executed? By the web application when a user makes a request or by the publisher service when an editor publishes the page?

Tridion templates or template building blocks are not executed when visitors make requests; as such there is no way to determine the URL of the request within the web application from a template simply because the template isn't executed inside the web application.

If you want to determine the requested URL by the visitor you need to write code that is executed by the web application at request time. You can emit this code from your razor template (as opposed to execute it). This will cause the published page to contain the code. Every time the published page is requested the code will be executed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.