Hi,
I had the same issue, but I managed to solve it with the following lines (Kentico 10) :
PortalContext.Clear();
CMSHttpContext.Current.Response.StatusCode = 404;
URLRewriter.RewriteUrl(RequestStatusEnum.PageNotFound, string.Empty, ExcludedSystemEnum.Unknown);
I'm not sure if it's a clean way, but it seems to work.
Best regards