Dear DynamicWeb,
How is this notification subscriber: "Standard.Page.NotFound" intended to work in DW10 as I cannot see that it is hitted in our solutions?
Best regards, Andes
Dear DynamicWeb,
How is this notification subscriber: "Standard.Page.NotFound" intended to work in DW10 as I cannot see that it is hitted in our solutions?
Best regards, Andes
Good one - it is dead. And it does not make sense. In DW9 it was notified when we had a URL that did not exist. But that can be any URL - e.g. /donotexist.php - which might once was a page, but and now the page is deleted - or it is just a wrong URL.
So in my world this notification has to marked as obsolete.
URLs and 404 is handled in the middleware now - if you can let me understand what you are trying to achieve, we can design something.
Could be UrlNotResolved notification - or something else. Though I am not fan of such notification subscriber as they can cause attack points of DOS. Most of the traffic hitting NotFound is robot traffic so it is very important not running expensive code. It can easily be a majority of requests to a website that are not real visitors, but just crap requests from all kind of things.
So carefulness is important to avoid problems.
So depending on what you want to do - you could simply inject middleware that matches what you want on a given URL - and if you do not want to do something on that URL, you just call next in the invoke - to inject middleware before DW: https://doc.dynamicweb.dev/documentation/extending/middleware/index.html
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-8.0
Dynamicweb will load this in its pipeline (after you have loaded yours) - having the NotFoundHandlerMiddleware be the very last one.
public void RegisterApplicationComponents(IApplicationBuilder app)
{
ArgumentNullException.ThrowIfNull(app);
app.UseRequestValidation();
app.UseAuthentication();
app.UseTrackingHandler();
app.UseLogOnHandler();
app.UseLogOffHandler();
app.UseEmailMarketingUnsubscribeHandler();
app.UseImageHandler();
app.UseCookieOptInHandler();
app.UseUrlIndexResetHandler();
app.UseRequestRewriteValidationHandler();
app.UseLockedSolutionHandler();
app.UsePageViewHandler();
app.UseSitemapXmlHandler();
app.UseRobotsTxtHandler();
app.UseLinkHandler();
app.UseRedirectHandler();
app.UseNotFoundHandler();
}
Dear Nicolai,
Thanks again for the detailed input — it’s much appreciated.
To clarify our use case a bit further:
We have two main scenarios we want to support with custom redirects:
Mapped redirects – where we perform a lookup in a custom table that maps old product URLs to new ones (based on SEO history).
Pattern-based redirects – where we derive the redirect dynamically based on certain URL patterns (e.g. query parameters or structure), and do not wish to store every permutation in a table.
We are looking into the middleware approach you suggested. However, could you elaborate a bit on how we ensure that our custom middleware is only invoked if Dynamicweb hasn’t already handled the request?
For our cases the approach with a UrlNotResolved notification sounds great and we would then be able to solve our tasks.
Any pointers or best practices for this would be greatly appreciated.
Best regards,
Anders Ebdrup
Hi Anders
Pattern based redirects is in the making and will be part of DW10 redirects shortly. Mapped redirects you can add to the redirect feature that already exists - and that will be handled by UseRedirectHandler just before the notfound handler. If you have the URLs in e.g. excel, you can simply import them to UrlPath table.
If you make your own middleware using iPipeline, it will run before anything in DW pipeline - there is no simple way to test if it is a valid DW URL. Writing your own middleware is probably not needed - you can re-use .net core: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting
We can add an extensibility point in the redirect middleware - that will execute if no DW url exists and there is no redirect defined in settings. But I am not a fan - as many, not you of course, will implement such an extension in a way that will cause serious performance issues... I do not think there is general awareness on how many requests there are. I just have a case from this weekend with more than 2.7mio 'dead' bot based requests to a site.
Example of a "Mapped redirect"
Hi Nicolai,
It sounds great with the "Pattern based redirects", which we will be looking forward to, but I would still very much like to have the extensibility point in the redirect middleware (and I am aware of the risk :-))
Hope you will add it?
Best regards, Anders
Hi Nicolai,
I am very curious to know whether, this has been prioritized yet?
Best regards, Andres
Hi again,
Can I please get an update on this one, as we are missing this feature in order to go live with a solution?
Best regards, Anders
You must be logged in to post in the forum