In this tutorial, you will find out how you can use the PublishedStateAssessor
API in order to figure out if an Episerver page is published, or not. Using this API will ensure that a page you might want to reference is active and it has been published. The two most common scenarios for needing to perform this type of check:
Creating a multi-language picker
Creating an SEO alternative URL picker
As the name implies, the IPublishedStateAssessor
can be used to figure out a page PublishedState
. To use the API in code, you can inject it via dependency injection. This process is exactly the same as another Episerver API, like IContentREpository
for example. I recommend that you use constructor injection to gain access to the API compared to using ServiceLocator
. ServiceLocator
is a dependency injection anti-pattern, however, to make this demo easy to understand, I'm using it:
As you can see the API is dead easy to use. Pass in the IContent
object and you get a boolean yes/no back depending on if the page is valid or not. That really is all there is to using this API. Happy Coding 🤘