Kentico 13: Preview url got 404 after migrated asp.net mvc site from 4.8 to .net 8

Jeff Shi asked on March 19, 2024 15:35

The preview link works when we use .net 4.8. After we migrate to .net 8 recently, we got 404 error . Here are key points we have 1. We are using Kentico 13 2. Got 404 when we try to access a url like: https://localhost:7044/cmsctx/pv/f211f3e1-5949-44c1-9842-c6526c92409f/culture/en-us/wg/a3e8d9bc-fae6-4a3f-b6e3-ca8477d229c4/h/a3ff0bcb6dd1fe16955a54c51caf423b22585a7abf6e628f28927bdb431591e3/-/insights/3m-test-article?uh=91675c48ae2b8c0f48fab1380a5492841371c4e9ce2905c0e73c40acf82e94fb

Looks like it is a routing issue, anything we missed?

Recent Answers


Brenden Kehren answered on March 19, 2024 16:02

I'm confused as to what you're talking about. Seems like you have a few different things going on. What is the exact version of Kentico you're working on? Kentico 13 2 is not a valid version. Is that Kentico version 13, refresh 2? Kentico version 13.0.2?

The CMS code is written in ASP.NET Forms and supports the .NET framework 4.8. The project does not support .NET 8. I do believe it does support C# 8.0 though.

The MVC code is typically .NET 6 or .NET 7. The MVC code will also support .NET 8 if you're on Kentico refresh 11 or higher.

What project did you "migrate" to .NET 8? The CMS or the MVC code?

0 votesVote for this answer Mark as a Correct answer

Jeff Shi answered on March 19, 2024 16:21

Hi Brenden, Thanks for the response. Here are more details: 1. We are using Kentico 13, not Kentic 132 (it is a typo, sorry) 2. We use this kind design: we have a MVC site which integrated to Kentico CMS. So the Kentico CMS was used as backend database. We just migrated our MVC code from .net4.8 to .net 8 directly.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 19, 2024 16:25

Got it, thank you for the clarification.

So the MVC project, was that ASP.NET MVC 5 before and now it's .NET 8? During that conversion process, did you be sure to update all code, including your Startup.cs file and the rest of your project references to use .NET core now vs. MVC5?

0 votesVote for this answer Mark as a Correct answer

Jeff Shi answered on March 19, 2024 17:25

Hi Brenden,

Yes, our mvc code is using .net 8 (.net core) now. Our initial .net 8 migration job finished. The mvc site and backend Kentico database works properly.

Since it is a big code change from .net 4.8 to .net 8, some small Kentico modules, like preview module we have before, it broke now.

Our new .net 8 code has Kentico updated. Here are some sample code for your reference var kenticoServiceCollection = builder.Services.AddKentico(features => { features.UsePreview(); }); … var app = builder.Build();

app.InitKentico();

app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseKentico(); app.UseCookiePolicy(); app.UseCors(); app.UseAuthentication(); app.UseWebOptimizer(); … app.UseEndpoints(endpoints => { endpoints.Kentico().MapRoutes(); });

Since the current error is 404, sounds like our mvc routing does not handle this preview url properly. So may be Kentico has some special configuration to set up the Preview url routing?

Thanks Jeff

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 19, 2024 17:43

My suggestion is to look at the base dancing goat startup.cs file and compare it to yours. Comment out any code that is not similar or the same, and test again.

0 votesVote for this answer Mark as a Correct answer

Jeff Shi answered on March 19, 2024 18:51

Thanks Brenden, I will take a look and let you know the results.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on March 20, 2024 06:38

What is the exact version, please, including hotfix - it is 13.0.x - what is the x? Also, when migrating from MVC5 to .NET Core, have you followed this documentation closely?

0 votesVote for this answer Mark as a Correct answer

Jeff Shi answered on March 26, 2024 15:24 (last edited on March 26, 2024 15:48)

Hi Juraj,

We are using version 13.0.133.

Our other team member handles the Kentico migration job. He is an very experienced Kentico developer. He follow the upgrade instruction. I have more information for your reference

Here are ALL the Nuget Kentico libraries we installed in our .net mvc core project

  • Kentico.Xperience.AspNetCore.WebApp 13.0.133
  • Kentico.Xperience.Libraries 13.0.133

Thanks

Jeff

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 26, 2024 16:30

Jeff,

The question still remains unanswered.

What migration was done?

Did you migrate from version 12 to version 13? Did you migrate from MVC5 to .NET Core? Did you do some other type of migration?

0 votesVote for this answer Mark as a Correct answer

Jeff Shi answered on March 26, 2024 18:00

Hi Brenden,

I see. We migrated from version 13 of MVC5 to version 13 of .NET Core.

Thanks

Jeff

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on March 27, 2024 05:52

So, after the upgrade from Kentico 12 MVC to Kentico 13 MVC5 - was everything working fine or not? This will help us to tell whether the issue arise after the upgrade or after the migration from MVC5 to .NET Core MVC. This will narrow down the options a lot. It seems that one or the other was not done right.

0 votesVote for this answer Mark as a Correct answer

Jeff Shi answered on March 27, 2024 14:02

Hi Juraj,

Want to clarify one thing, we finished Kentico 12 MVC to Kentico 13 MVC a few months ago. It is not the issue I asked in this ticket.

The issue we have right now is we are migrating our MVC website from Kentico 13 MVC (.net framework 4.8) to Kentico 13 MVC Core (.net framework 8.0).

So far, the Kentico MVC Core (.net 8.0) migration finished and the website runs properly. But we still have some small issues. Kentico Preview is one of them.

If I tried to access Kentico Preview url, like this:

https://localhost:7044/cmsctx/pv/f211f3e1-5949-44c1-9842-c6526c92409f/culture/en-us/wg/a3e8d9bc-fae6-4a3f-b6e3-ca8477d229c4/h/a3ff0bcb6dd1fe16955a54c51caf423b22585a7abf6e628f28927bdb431591e3/-/insights/3m-test-article?uh=91675c48ae2b8c0f48fab1380a5492841371c4e9ce2905c0e73c40acf82e94fbThe

I got the 404 error (But this url works before we migrate, so it means we missed something in our new MVC Core project, Maybe we missed a Nuget Kentico library?). It sounds like Kentico Preview URL (https://localhost:7044/cmsctx/) has routing issue. Hope this clue will help you to identify the issues.

Thanks

Jeff

0 votesVote for this answer Mark as a Correct answer

Jeff Shi answered on March 27, 2024 18:25

Hi Juraj,

Regarding the 404 issue we have, it looks like the Kentico Preview Routing code does not setup right in our MVC Core project.

Here is the Kentico Preview Route: https://localhost:7044/cmsctx/. In Kentico .net Core Mvc website, I guess a Kentico library (I do not know which one) should hijack this route in the pipeline process and parse out the right Controller and Action to handle it, but it does not work and it throws http 404 error now.

Any suggestion about how to trouble shooting will be helpful.

Thanks

Jeff

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 27, 2024 20:30

When you migrated from MVC5 to .NET Core, did you remove the unnecessary files that are added by Kentico and MVC5? For example, the /Kentico and /Scripts folders and their contents are not needed in .NET Core. However, you may want to check those locations to make sure there aren't any project specific files in there.

I don't beleve you have any control over how the preview pages are routed or set up. This is all internal and not configurable. However, there is a lot of javascript and Kentico files that can cause problems if you've not properly migrated the code.

0 votesVote for this answer Mark as a Correct answer

Jeff Shi answered on March 27, 2024 22:45

Hi Brenden,

Thanks for the answers.

Since I did not handle the Kentico .net MVC core migration. So I may not be able answer this question correctly. Here is what I found:

We still have this Kentico folder under the MVC root folder in our .net mvc core project. There are a few sub folders under it, here are the brief of those sub folders:

  • Content folder: It contains some Kentico Components folders and code, like Widgets, Selectors, FormComponents...

  • Models folder: it contains all generated Kentico page models. But I did not see project setting files here

  • Providers folder: it contains all generated Kentico database query code. But I did not see project setting files here

  • Scripts folder: many js files in it.

Did you see any issues of those files?

Thanks Jeff

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 27, 2024 23:19

I'd install a version 13 MVC site and compare the files in those folders to what is in the base setup of an MVC site. I understand there are a lot of files in both of those directories but you need to determine which ones are for v13 .NET Core and which ones were from MVC5 and remove the unnecessary MVC5 files.

0 votesVote for this answer Mark as a Correct answer

Jeff Shi answered on March 27, 2024 23:44

Thanks Brenden, I downloaded DancingGoat mvc core source code and I did not find any code which mentioned how to setup Kentico Preview feature. It may requires deeper research.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 27, 2024 23:49

You don't need the Core version, you need the MVC5 version to remove those files in your Core version from MVC5 that should not be there.

Setting up the preview mode is essentially 1 line in Core. What I'm saying is you have extra files from v12 and MVC5 that are being compiled into your Core project and causing problems.

0 votesVote for this answer Mark as a Correct answer

Jeff Shi answered on March 28, 2024 17:31

Hi Brebden,

About 1 line code to setup preview mode, you mean this?

features.UsePreview();

Thanks for the Core version comments.

Jeff

0 votesVote for this answer Mark as a Correct answer

Jeff Shi answered on March 28, 2024 17:35

Hi Juraj,

Not sure if it is possible to find out why Kentico library did not process the preview url (/cmsctx)?

Thanks Jeff

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 29, 2024 01:45

Yes Jeff, that one line sets up preview mode.

As stated you need to compare a couple vanilla project installs and remove the unnecessary version 12 files that weren't removed. This should resolve your issue.

0 votesVote for this answer Mark as a Correct answer

Jeff Shi answered on March 29, 2024 16:01 (last edited on March 29, 2024 16:19)

Brenden,

The issue was solved by our original developer who migrated the Kentico to core mvc. The issue is he compared DancingGoat code with our code. He found we did put the key to the settings section in appsetting.json file, not in the root, this caused Kentico cannot find the key.

"appSettings": {

"CMSHashStringSalt": "XXXXXXX"

}

Also, if Kentico preview library cannot find this key, hope the library can throw an error or log error. This should be a good for end user to find issue quick!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.