Try our conversational search powered by Generative AI!

How to tell if request is in preview mode with episerver 10



i am working on upgrading a site from version 7.5 to version 10 and i'm struggling to work out a solution to an error i am getting. There is some code that is used to find out if the request is in preview mode which was working in 7.5 but doesn't work in version 10:

EPiServer.Web.Routing.Segments.RequestSegmentContext.CurrentContextMode == ContextMode.Preview

the problem is that RequestSegmentContext doesn't exist in EPiServer.Web.Routing.Segments in version 10 ( so this code won't build. I have had a play around with some other options and searched online but i can't work out the correct way to determine if the request is in preview mode.

this seems like a simple & common bit of code so i'm wondering if anyone has found a way to do this in episerver 10?



Nov 17, 2016 15:43

Hi Sam,

A lot of undocumented implementations were moved into sub-namespaces (.Internal) with EPiServer 10.

The same feature should still be available and usable under the new namespace:


Edited, Nov 17, 2016 20:21

Depending on where you wanna use this code, there is an extension method called GetContextMode on RequestContext. RequestContext is usually available, so I would recommend using that method instead since it's not an internal API. Please see

Nov 17, 2016 22:13
fuji - Oct 28, 2019 16:11
Thank you for the answer, however I've struggled a bit trying to understand it and then this worked for me - ControllerContext.RequestContext.GetContextMode(); - but it returns "Edit" while in "Preview" mode.


requestContext.GetContextMode() is exactly what i was looking for.

Thanks for your help Johan!

Nov 18, 2016 10:06

There is also an abstraction EPiServer.Web.IContextModeResolver registered in IOC container that can be used.

Nov 18, 2016 14:54
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.