CMS 12 upgrade only shows 404 for any path

Vote:
 


Hi,

We are in the process of upgrading from CMS 11 to CMS 12. Errors are fixed and we can compile and run. Program.cs and Startup.cs was largely taken from the Alloy template to have something to start with. Database filled with a lot of pages from CMS 11.

When starting the application locally (and testing against local IIS) I get a 404 Not found when trying paths with known pages. Some things I have tested:

- I know that the page exists in the database, and has controller, view etc.
- Browsing to https://localhost:54806 hits StartPage (as in the routing directive), with currentPage is null. I tried getting a page by pageId of a known existing page in the StartPage controller to try to see if the database connection was OK and it returned the requested page, so database connection works.
- http://cms12.local/EPiServer redirects to http://cms12.local/EPiServer/Shell/Readonly

Log shows:

info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/2 GET https://localhost:54806/path/to/page - - -
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/2 GET https://localhost:54806/path/to/page - 404 0 - 3.4802ms
info: Microsoft.AspNetCore.Hosting.Diagnostics[16]
      Request reached the end of the middleware pipeline without being handled by application code. Request path: GET https://localhost:54806/path/to/page, Response status code: 404

Startup class:

public class Startup
{
    private readonly IWebHostEnvironment _webHostingEnvironment;

    public Startup(IWebHostEnvironment webHostingEnvironment)
    {
        _webHostingEnvironment = webHostingEnvironment;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        services
            .AddCmsAspNetIdentity<ApplicationUser>()
            .AddCms()
            .AddFind()
            .AddSingleton<MatcherPolicy, CustomMatcherPolicy>()
            .AddEmbeddedLocalization<Startup>();

        services.AddSession(options =>
        {
            options.IdleTimeout = TimeSpan.FromSeconds(10);
            options.Cookie.HttpOnly = true;
            options.Cookie.IsEssential = true;
        });
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseRouting();
        app.UseSession();
        app.UseStaticFiles();
        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(name: "default", pattern: "{controller=StartPage}/{action=Index}/{id?}");
            endpoints.MapRazorPages();
        });
    }
}

Program class:

public class Program
{
    private static IHost _host;
    public static IHost host
    { get { return _host; } }
    public static void Main(string[] args) => CreateHostBuilder(args).Build().Run();

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureCmsDefaults()
            .ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
}
#316023
Jan 22, 2024 16:20
Vote:
 

Hi Tony

I don't see MapContent() in your endpoint configuration. Add endpoints.MapContent(); before MapControllerRoute
#316061
Jan 22, 2024 23:33
Vote:
 

Hi Vincent, thanks for replying. I had MapContent when testing around and it didn't work. But the order was important - it had to be before MapControllerRoute. It solved the problem. Many thanks :)

#316077
Jan 23, 2024 10:17
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.