Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

404 for expired pages - for editors as well?

Vote:
 

Hi!

We've upgraded our CMS and now have the feature where expired pages return 404. I understand why this is so, but our editors are a little bit confused.

Before, when you we're logged in as an editor, you could "preview" an expired page by browsing to it. Of course, if you were an ordinary user you would end up on the login screen.

What is best practice when it comes to previewing pages? Should you use the preview mode inside the editor (basically clicking on the button with the box and magnifying lens)?

#179764
Jun 21, 2017 9:07
Vote:
 

Which EPiServer version is this? I can confirm that in samaple alloytech expired pages are still accessible by editors..

#179888
Jun 24, 2017 7:15
Vote:
 

The title in admin mode says EPiServer CMS 10.10.0.0.

Inside EPiServer's edit mode the page's displayed fined. However, if I'm logged in and click on "Show on website" I end up with a 404. The same goes for if I'm logged in and browse to the page, entering the address manually.

I've recently upgraded so maybe there's something else interferring.

#179891
Jun 24, 2017 10:50
Vote:
 

Oh this case, I think it was mentioned somewhere in breaking changes..

#179894
Jun 24, 2017 19:48
Vote:
 

With help from awesome fellow (Daniel Ovaska), I refreshed my memory and found that piece of code.

So, your page controller inherits from EPiServer.Web.Mvc.PageController<T>, which iherits from EPiServer.Web.Mvc.ContentController<T>, which is decorated with attribute [AuthorizeContent], which has method implementaion - OnAuthrization, which checks whether routed content could not be loaded, or content is not routable (meaning it's expired). If so and current user is not in EditOrPreview mode - you will get back HttpNotFoundResult().

If you really want to change this behavior (I mean there has to be really good reasons for EPiServer to check this functionality from older version), one of the option would be to enroll your own page controller that inherits directly from ActionControllerBase (parent of ContentController) with custom [AuthorizeContent] attribute that does not blow up with 404, but instead does your required magic.

#179946
Jun 26, 2017 18:47
Vote:
 

Thanks Valdis!

I totally agree with you - there must be a good reason for EPiServer to make this change. Me, I don't work in edit mode as much as our editors so I guess the change is more noteable to them. It's clearly better with a 404 to the outside world. On the other hand, when you're logged in as an editor, maybe you should be able to view the page.

Unfortunately for me I'm currently maintaining a website with mixed content: Web Forms and MVC. cry

Edit: Regarding the breaking change, I think it's this one CMS-1320.

#179954
Edited, Jun 27, 2017 8:19
Vote:
 
public class ImprovedPreviewRoutableEvaluator : IRoutableEvaluator
{
     private readonly IContextModeResolver _contextModeResolver;
     private readonly IPublishedStateAssessor _publishedStateAssessor;

     public ImprovedPreviewRoutableEvaluator(IContextModeResolver contextModeResolver, IPublishedStateAssessor publishedStateAssessor)
     {
         this._contextModeResolver = contextModeResolver;
         this._publishedStateAssessor = publishedStateAssessor;
     }

     public bool IsRoutable(IContent content)
     {
         if (!this._publishedStateAssessor.IsPublished(content))
         {
                var editMode = this._contextModeResolver.CurrentMode.EditOrPreview();
                return editMode || content.QueryDistinctAccess(AccessLevel.Edit);
         }
             
         return true;
     }
}

--------------------------

container.For<IRoutableEvaluator>().Use<ImprovedPreviewRoutableEvaluator>();

So basically don't just check if you are in edit/preview mode. Also check if you have edit access to the page and then allow to view it even if it's not currently published.
Need a small change in the IRoutableEvaluator + register it in ioc container to make Episerver use it instead. Fun question! Also good example of that Episerver is getting better and better architecture since Episerver 7 that allows you to do stuff like this :)

#179959
Jun 27, 2017 10:33
Vote:
 

oh, awesome - that's another way to customize this behavior. forgot about evaluator.. my memory is getting worse :))

#179978
Jun 27, 2017 15:32
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.