-4

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

2
  • what research have you done and what have you tried? – Nickoli Roussakov Jul 4 '15 at 16:46
  • I have added HttpContext.Current and Request.Url.ToString() in my razor code but it gives me Null Reference exception. – Sudip Ghorai Jul 6 '15 at 10:34
6

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.

1
  • 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. – Sudip Ghorai Jul 7 '15 at 9:14
1

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, privacy policy and cookie policy

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