Kentico 12 MVC Page Preview 404 Errors: Troubleshooting tips

   —   

When building your MVC site with Kentico, it’s possible you may run into page preview 404 or ” VirtualContextHashOrUserValidationFailed ” errors, with the latter message being somewhat misleading as to the cause of the error. Since there are more than a few things to check, this article will equip you with troubleshooting tools preparing you for battle with the page preview errors.

Getting Into the Troubleshooting

To start, we will review some good general practice guidelines for troubleshooting, especially after hotfixes or upgrades. First, restart both admin and MVC applications and re-sign macro signatures per the re-signing macros documentation. If this has not solved the issue, please review our documentation on adding preview mode support to your project to ensure the appropriate steps were followed. Some of the more common mistakes are: forgetting builder.UsePreview() in the Application_Start method, and retrieving the latest versions of pages described in the loading the latest versions of pages documentation.

Common Culprits

Mismatched CMSHashStringSalt values between sites:

  • Check to make sure both your Admin and MVC sites have uniform CMSHashStringSalt values in the AppSettings section of your web.config files.

Admin and MVC applications on different versions:

  • This is most often seen after a hotfix or an upgrade. Check to make sure your MVC NuGet packages and Admin applications are running on the same version and hotfix. Furthermore, you can run this query in the database to ensure the versions are all uniform:
    SELECT KeyName AS [Description], KeyValue AS [Value]
    FROM CMS_SettingsKey
    WHERE KeyName IN ('CMSDBVersion', 'CMSDataVersion', 'CMSHotfixVersion',  'CMSHotfixDataVersion')
  • Note: If your version is below 12.0.30 you can remove ‘CMSHotfixDataVersion’ from the query.
  • Alternatively, you could also use KIM (Kentico Installation Manager) to view version/hotfix info

“VirtualContextHashOrUserValidationFailed” Corrupt or bad references in Kentico.AspNet.Mvc.Libraries NuGet packages:

  • This error is most commonly seen after a hotfix/upgrade. Typically, uninstalling the Kentico.AspNet.MVC.Libraries NuGet package and reinstalling it will fix this problem. Make sure to restart both applications after the change.

Presentation URL in the “Sites” application set incorrectly:

Page type URL Pattern set incorrectly

  • Make sure the page type URL pattern is set appropriately according to the documentation: Specifying the URL pattern for content-only pages. Additionally, check your routes.config file and check the route and controller associated with the URL pattern, place a breakpoint in the controller, and double check to ensure your controller is pointed to the right path and is being hit.
  • In an example down below, I have a basic Home controller that’s using the generatedProvider method: GetHome(string nodeAliasPath, string cultureName, string siteName) where nodeAliasPath is the alias path to the content tree node that represents the page, so in my example it would be /Home. Additionally, I have a route pointed to the HomeController and index action that’s getting hit.




 

Preview Link Expiration issues:

  • This is not strictly related to 404 errors, but is relevant to preview issues. If you’re sending preview links to unpublished pages or are having issues with preview links, check your version. If you’re using versions prior to 12.0.47, then you should try to add the CMSPreviewLinkExpiration key to your web.config file and increase the expiration value. This key allows you to adjust your admin interface URL’s expiration, and the value reflects the amount of minutes. After 12.0.47, this key is added automatically by Kentico, so hotfixing the Admin and MVC projects to the latest version is also recommended: 
    <add key="CMSPreviewLinkExpiration" value="240" />

If none of the above solutions have helped your issue, feel free to open up a ticket for our 24/7 support team and we will be happy to assist you!

Share this article on   LinkedIn

Jamie Leask

Kentico Support Engineer