RedDot CMS Blog
rdb: Getting a Page Preview from outside the CMS
This blog post is inspired by “Shawn”. Hope this helps.
Some background first I think. There are 2 ways to log in to CMS – normal and integrated. An integrated login means that your Windows user account is passed silently by your browser to the CMS server and you don’t need to type in a username or password.
If you’re organisation uses Windows and you aren’t using integrated login slap yourself across the face now for being lazy, then read up on how to configure it. Your users will thank you tomorrow. It takes about 10 minutes to set up and is much better for security (since it’s harder to forge).
If you are using integrated login already this is super-easy and you’re probably wondering why I’m bothering to blog about this at all. If you’re reading this, therefore, it stands to reason that you’re not.
I am going to assume that you, reader, already has the capabilities required to locate the GUID of the page you want a preview of. In some cases you will require the LinkFromGuid as well to provide CMS with the context it needs to render the page properly. I have had success with the following minimalist URL:
[If you use Action=Preview it will work without the Mode parameter]
[If you have lots of projects you should send the ProjectGuid parameter too]
If you want the full thing for your case simply pop a preview window, right-click the page and hit Properties. Triple-click (yes, you read that right) on the URL to select even the bits that fall off the screen and you can copy/paste into your editor of choice.
There are 3 approaches…
1. RQL => Hard
You can use the following RQL to get the preview HTML of a CMS page:
<IODATA loginguid="[LoginGuid]" sessionkey="[SessionKey]">
<PREVIEW mode="0" projectguid="[ProjectGuid]" versionguid="[VersionGuid]" isolated="[Isolated]" generatedate="[AsAtDate]" templateguid="[templateGuid]" rights1="[UserRights]" loginguid="[LoginGuid]" url="[URL]" querystring="[QueryStringParams]" />
This is hard for a few reasons.
Firstly there is quite a lot of information you are going to need to create an RQL like this, not least of which you are going to have to login to the RQL system which will require credentials and you may not want to ask your user for them. This is where integrated login comes in.
2. Integrated Login => Super Easy
Simply point your user at the URL. Since the browser and RedDot do the login in the background it should just work. Assuming you already have the GUIDs you need from somewhere else. If not, you first need to run some RQL to get them. This is where the Integrated Login plugin I talked about before comes in handy. Using that you can silently log your user into RQL, execute whatever steps are required to get your GUIDs, and redirect the user to the correct URL.
3. Standard Login => Moderate
The problem here is that you need to get credentials off your user. If you don’t log your session in to RedDot you will get a nasty error message when you launch the preview URL to the effect that LogonGuid and SessionKey are missing. That’s because these are server variables that RedDot is expecting to have when it attempts to generate the preview. The only way forward is to get them, and that means logging in.
You need to do this in ASP because we need to set Session variables for the CMS to use. It is possible to get/set session variables with other languages but it’s way harder than if you just use ASP. Here are the steps to follow:
- Create a new plugin ASP page – this is the page you will call to perform all the tasks required to access the preview
- On the first pass of the page show login username and password boxes for the user to complete
- On the second pass use that information to form the login RQL command
- Do other steps to get the GUIDs you need to form the preview URL – this may include asking the user for more information, or you could supply it as parameters in the originally called URL
- Redirect the user to the preview URL
- Set your external app to call your plugin with the correct parameters
- Since you’re not calling this plugin from CMS’ SmartTree/SmartEdit there is no need to register it in the normal way.
The reason we do it as a plugin is that plugins run within the application scope of the CMS. That means session data stored in a plug is available to the main CMS, including the LogonGuid and SessionKey that get generated as part of the RQL login process. We can save these to Session variables so the preview page can get at them.
You can download a sample ASP file here.