UseStatusCodePagesWithReExecute conflict with Admin

2024/10/30 3:23 PM

In previous sites, we would use the app.UseStatusCodePagesWithReExecute("/error/{0}") to have a custom error page and handling for the website, however now that the admin and website are the same, this breaks some of Kentico's admin functionality. Anyone have any idea of how to have a custom error message only for the website but not touch any admin stuff?


Environment

  • Xperience by Kentico version: 29.6.0
  • .NET version: 8
  • Execution environment: Local

Answers

2024/10/30 3:55 PM
Answer

I have it working with the following order:

var app = builder.Build();

app.InitKentico();

app.UseStaticFiles();

app.UseKentico();

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
    app.UseMiniProfiler();
}

app.UseStatusCodePagesWithReExecute("/error/{0}");

Maybe try make sure it is registered after InitKentico/UseKentico?

2024/10/30 3:56 PM

Liam answered it correctly, but to give a bit more context, i needed to add it AFTER the app.UseKentico(), that did the trick!

2024/10/30 7:40 PM

Thanks @liamgold

And, as a surprise to no one 😅 there is an example in the Kentico Community Portal.

To answer this question, you have to login first.