Class PreviewService
Provides functionality for managing content preview mode.
Inheritance
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
Syntax
public class PreviewService : IPreviewService
Remarks
Preview mode allows backoffice users to view unpublished content changes as they would appear on the front-end website. This implementation uses secure cookies with SameSite=None to support cross-site preview scenarios.
Constructors
View SourcePreviewService(ICookieManager, IPreviewTokenGenerator, IServiceScopeFactory, IRequestCache)
Initializes a new instance of the PreviewService class.
Declaration
public PreviewService(ICookieManager cookieManager, IPreviewTokenGenerator previewTokenGenerator, IServiceScopeFactory serviceScopeFactory, IRequestCache requestCache)
Parameters
| Type | Name | Description |
|---|---|---|
| ICookieManager | cookieManager | The cookie manager for handling preview cookies. |
| IPreviewTokenGenerator | previewTokenGenerator | The generator for creating and validating preview tokens. |
| IServiceScopeFactory | serviceScopeFactory | The factory for creating service scopes. |
| IRequestCache | requestCache | The request cache for caching preview state per request. |
Methods
View SourceEndPreviewAsync()
Exits preview mode for the current request.
Declaration
public Task EndPreviewAsync()
Returns
| Type | Description |
|---|---|
| Task | A task representing the asynchronous operation. |
IsInPreview()
Determines whether the current request is in preview mode.
Declaration
public bool IsInPreview()
Returns
| Type | Description |
|---|---|
| bool |
|
TryEnterPreviewAsync(IUser)
Enters preview mode for a given user.
Declaration
public Task<bool> TryEnterPreviewAsync(IUser user)
Parameters
| Type | Name | Description |
|---|---|---|
| IUser | user | The user entering preview mode. |
Returns
| Type | Description |
|---|---|
| Task<bool> |
|
TryGetPreviewClaimsIdentityAsync()
Attempts to get the claims identity for the current preview session.
Declaration
public Task<Attempt<ClaimsIdentity>> TryGetPreviewClaimsIdentityAsync()
Returns
| Type | Description |
|---|---|
| Task<Attempt<ClaimsIdentity>> | An attempt containing the claims identity if in preview mode; otherwise, a failed attempt. |