1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Safely Showing Previous Vesrison of Pages

Safely Showing Previous Vesrison of Pages

7 posts, 0 answered
  1. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    21 Nov 2009
    Link to this post
    One of my major requirements is showing previous versions of an ICmsPage without authentication. The problem is, it seems like the Telerik.Cms.Web.PreviewPage class is required to view an old version of a page.

    Is there a way to pull up old versions using InternalPage?

    Thanks,
    Jeff
  2. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    21 Nov 2009
    Link to this post
    To clarify- by "pull up," I mean with a URL parameter. The one in the page administration area looks like this:

    http://localhost/my-document-with-many-revision.aspx?cmspagemode=preview&pageversion=6&rwndrnd=0.2584165603175159

    Is there a way where I can use pageversion=6 without having to use cmspagemode=preview?

    Thanks again.
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    23 Nov 2009
    Link to this post
    Hello Jeff,

    It would be possible if you create a custom class that inherits from InternalPage. Then you have to override CreateChildControls method. After you call the base you need to clear the controls using this.Controls.Clear();. Then get the current version from a QuesryString - say "PageVersion"

    string qs = HttpContext.Current.Request.QueryString["PageVersion"];

    Then create a new instance of ICmsPage where you pass the version

    IStagedPage stagedPage = page.GetVersion(version);

    and finally call AddPageControls

    this.AddPageControls(
                    stagedPage,
                    CmsHelper.FindContentPlaceHolders(this.Master));

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  4. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    24 Nov 2009
    Link to this post
    Hi Ivan,

    I didn't have any luck getting the code you provided working. However, it did give me some ideas and I got it working using a similar approach.

    Can tell me if I'm doing anything I wrong in the following code?

    First off, I'm overriding CreateChildControls in the Master page rather than class derived from InternalPage. The reason is the Master page contains the ContentPlaceHolder that I wish to populate with old page content.

                if (!string.IsNullOrEmpty(Request["version"]) && PageEx != null
                { 
                    int nVersion = -1; 
     
                    if (int.TryParse(Request["version"], out nVersion)) 
                    { 
                        ICmsPage CurrentPage = /*(get a reference to your CMS page somehow)*/ 
                        IStagedPage oldversion = CurrentPage.GetVersion(nVersion); 
     
                        // "Content" is the ContentPlaceHolder to receive the content of the old version of the page 
                        Content.Controls.Clear(); 
                        foreach (CmsWebControl c in oldversion.Controls) 
                            Content.Controls.Add(c.LoadControl()); 
                    } 
                } 
     

    I realize that if the saved page had multiple placeholders (mine doesn't), I would have to check c.ContainerID and add the control to the appropriate placeholder.

    So, am I missing any steps here? Can you think of any reason why this is a bad idea?

    BTW, the AddPageControls method you provided in your sample code appears to be a private member of InternalPage. I didn't have access to it in my derived class.

    Thanks,
    Jeff
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    24 Nov 2009
    Link to this post
    Hello Jeff,

    You will not able to achieve this working with the master page because your code will be overridden by the logic in InternalPage.

    Below is a sample code:

    public class InterlanPageCustom : InternalPage
    {
        public InterlanPageCustom()
        {
        }
     
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            this.Controls.Clear();
            ICmsPage page = base.CmsPage;
     
            string qs = HttpContext.Current.Request.QueryString["PageVersion"];
            if (!String.IsNullOrEmpty(qs) && page != null)
            {
                int version = Int32.Parse(qs);
                IStagedPage stagedPage = page.GetVersion(version);
                this.AddPageControls(stagedPage, MyHelper.FindContentPlaceHolders(this.Master));
            }
            
        }

    AddPageControls is not private and when InternalPage is override. Note that you need to create a helper class that is looking for all controls in the master page of your page (in the sample called "MyHelper".  The helper class should be of type Dictionary<string, ContentPlaceHolder> FindContentPlaceHolders(MasterPage master). Generally InternalPage is used to show only published pages and this is why we have moved the history-view logic in "preview" mode.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    24 Nov 2009
    Link to this post
    Hi Ivan,

    I'm still not able to get the code working in the InternalPage-derived class. Here's what I'm seeing:

    *  Controls.Clear() wipes out the MasterPage control from the Page.Controls collection. Even if the content in the ContentPlaceHolder were replaced, it doesn't show up because the ContentPlaceHolder is a child of the MasterPage.

    *  I misspoke when I said AddControls was private. What I meant to say is FindContentPlaceHolders is a private member of CmsHelper. Regardless, I created a Dictionary containing the placeholder using its ID as the key. When I look at the placeholder in Quick Watch directly after calling AddControls, it still contains the most recent version of the page.


    Meanwhile, I'm having success using the code I provided in the MasterPage CreateChildControls. Even on a postback (where CreateChildControls is called earlier), I'm still getting the old version of the page.

    Your concern about InternalPage overwriting the content isn't happening for me.

    My only worry is doing it this way may have other unintended consequences down the road.

    Thanks,
    Jeff
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    24 Nov 2009
    Link to this post
    Hi Jeff,

    AddPageControls accepts as a parameter the cms version you pass from the qurystring. I checked the code at my end and the correct version was loaded. Of course I am working with custom internal page class. The FindContentPlaceHolders should look for each control in the controls collection, its ContentPlaceHolder and the ids. Othwewise you cannot get the version you are looking for.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
7 posts, 0 answered