Generating a Preview Link in Code

The Agility Content Manager automatically generates an agilitypreviewkey and appends this to the page path of the page you are intending to view - i.e.{key}. This allows Agility users to preview website pages.

However, there might be some cases where you may want to generate preview links in your own application. This can be helpful when you are integrating with other services, building custom reports, workflows, or managing content outside of Agility.

You can do this by using the code block below to generate your own preview key and append it to the target page URL.

//get your website security key and build a byte array
string securityKey = Settings.CurrentSettings.WebsiteSettings[AgilityContext.WebsiteName].SecurityKey;
byte[] data = UnicodeEncoding.Unicode.GetBytes(string.Format("{0}_{1}_Preview", -1, securityKey));

//hash it & convert to base64
SHA512 shaM = new SHA512Managed();
byte[] result = shaM.ComputeHash(data);
string previewKey = Convert.ToBase64String(result);

//generate preview link
string previewUrl = string.Format("{0}", previewKey);
0 out of 0 found this helpful



Please sign in to leave a comment.