Folder redirect

Alex Koshel asked on October 11, 2025 20:42

I have many Type:Folders and they have their own URLs, for example, http://localhost/_pages/. How can I globally implement 404 page display for all these types? Using kentico 11 portal template

Recent Answers


Juraj Ondrus answered on October 12, 2025 04:43

I would use IIS URL Rewriting rules for better performance. Or, if you want to do it on Kentico app level, use the request event handler and check the requested URL and then perform desired action.

0 votesVote for this answer Mark as a Correct answer

Alex Koshel answered on October 13, 2025 21:18

ublic class FolderHandrelModule : Module { public FolderHandrelModule() : base("FolderHandrel") {

}
protected override void OnInit()
{
    base.OnInit();
   RequestEvents.Authorize.Execute += End_Execute;
}

private void End_Execute(object sender, EventArgs e)
{


    var node = DocumentContext.CurrentDocument;

    if (node != null && node.ClassName.Equals("CMS.Folder"))
    {           

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.StatusCode = 404;
            HttpContext.Current.Response.TrySkipIisCustomErrors = true;

            HttpContext.Current.Server.Execute("\404error");

            HttpContext.Current.Response.End();

    }
}

} I'm using this code, but there's no result. Perhaps I need to change the subscription event. I used the Prepare event, but it didn't help either.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on October 14, 2025 04:59

0 votesVote for this answer Mark as a Correct answer

Alex Koshel answered on October 16, 2025 17:04

In the debugger, when the page is launched, the event is not tracked.

0 votesVote for this answer Mark as a Correct answer

Alex Koshel answered on October 16, 2025 21:16

What are the best practices for 404, 500 errors?

0 votesVote for this answer Mark as a Correct answer

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