How to get a media by url without hitting the database?
Hello...
I need to correct a middleware that checks a media property for each request.
It's currenlty working but it tells me that the method I use is obsolete and will be removed on next version (14) of Umbraco.
I should obtain a media by its url but without hitting the db.
Can you help me?
How to get a media by url without hitting the database?
Hello... I need to correct a middleware that checks a media property for each request. It's currenlty working but it tells me that the method I use is obsolete and will be removed on next version (14) of Umbraco.
I should obtain a media by its url but without hitting the db. Can you help me?
I currently use this code
IPublishedMediaCache? mediaCache = umbracoContextReference.UmbracoContext.Media;
var foundMedia = mediaCache.GetSingleByXPath($"//umbracoFile[contains(., '{context.Request.Path}')]");
Thank you so much
You could probably just get all descendants with umbracohelper and filter them with LINQ. Something like:
And tweak it a bit to ignore case etc
is working on a reply...