rickbutterfield / Umbraco.Community.BlockPreview

Easy to use rich HTML backoffice previews for the Umbraco Block List and Block Grid editors.
MIT License
15 stars 10 forks source link

UmbracoContext.IsFrontEndUmbracoRequest() Always True #56

Closed markadrake closed 4 weeks ago

markadrake commented 3 months ago

Which Umbraco.Community.BlockPreview version are you using?

1.8.4

Which Umbraco version are you using? For example: 10.4.0 - don't just write v10

13.3.2

Bug summary

I'm attempting to add some code to a razor file that should only render if it's being rendered in the backoffice.

I believe the approach in the past was to reference UmbracoContext.IsFrontEndUmbracoRequest().

I tried to use this but it actually returns true when a razor partial is rendered from the backoffice.

Steps to reproduce

Add this to any razor file you are trying to render in the backoffice:

@if (!UmbracoContext.IsFrontEndUmbracoRequest())
{
    <p>Hello Backoffice!</p>
}

Expected result / actual result

I'd expect "Hello Backoffice!" to render only in the backoffice preview. It currently doesn't render anywhere. IsFrontEndUmbracoRequest() always returns true.

rickbutterfield commented 2 months ago

Hey @markadrake, I think my suggestion is similar to what has been suggested on the linked issue in the Umbraco-CMS repo.

You are probably best using @Context.Request.IsBlockPreviewRequest() in your Razor views where you want to render something specific for the preview in the backoffice but not on the front end.