Try our conversational search powered by Generative AI!

Can i find out in what page a block is rendered?


I know a block can belong to a lot of different pages but could it be possible to somehow, during the rendering of the view, use this statement to get the context in which it is in or some other method.


When I use the above statement I get SysRoot content link so it obviously does not work as I want it to...

Any suggestions?

Dec 05, 2013 14:49
Dec 05, 2013 15:50

Hi Joshua!

Thanks for the link but this link is old (no page)... 

Dec 06, 2013 9:21

Correct link is

You could use it like this:


            var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
            var references = contentRepository.GetReferencesToContent(someReference, false);


Dec 06, 2013 10:53

Ok, I have tried this out:

var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
var references = contentRepository.GetReferencesToContent(((IContent) Model).ContentLink, false);


But that gives me references to all content that references this block instance. 
But is it somehow possible for a block to find out (in its cshtml file for instance) in what page it is rendered at that moment?

The thing i would like to achieve is for my block to find out under what SiteRoot (Start Page) it is rendered so it can get some properties from that SiteRoot. One solution is to add a property to my block that holds a PageReference to the SiteRoot but if I would like to use one instance of my block on several different SiteRoots then it will fail..

Any suggestions?

Edited, Dec 06, 2013 15:04

Ah, check out this forum topic on how to get the current page:


Dec 06, 2013 15:16

Thanks! It works exactly as I want it:

var pageRouteHelper = EPiServer.ServiceLocation.ServiceLocator
var currentPage = pageRouteHelper.Page;


Dec 09, 2013 9:25
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.