Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas Beckert 193 posts 469 karma points
    Apr 07, 2020 @ 15:50
    Thomas Beckert
    1

    Using ClientDependency Filters to manipulate HTML

    Hi,

    I want to manipulate the html-code before it gets send back to the client - in my case, I want to replace all e-Mail addresses with a certain javascript-Code. Anyway, it works well with the cool code-snippet of Lee Kelleher, found here for V8: https://leekelleher.com/2020/01/clientdependency-filters-manipulate-html/?fbclid=IwAR2NCF6B-qaD8Srq1ULea0ZsT-360jI7bQUevbMGrfA2eABo3hkQkWVwYac

    I use it in V7, so only simple changes need to be made:

    namespace Umbraco.Community.Web
    {
        public class UpdateHtmlExampleComposer : ApplicationEventHandler
        {
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                ClientDependencySettings.Instance.ConfigSection.Filters
                    .Add(new ProviderSettings(nameof(UpdateHtmlExampleFilter), typeof(UpdateHtmlExampleFilter).GetFullNameWithAssembly()));
            }
        }
    
    public class UpdateHtmlExampleFilter : IFilter
    {
        public HttpContextBase CurrentContext { get; private set; }
    
        public bool CanExecute()
        {
            return Umbraco.Web.UmbracoContext.Current?.IsFrontEndUmbracoRequest == true;
        }
    
        public void SetHttpContext(HttpContextBase ctx) => CurrentContext = ctx;
    
        public string UpdateOutputHtml(string html)
        {
            // TODO: Do your HTML updates in here! 
            // ------------------------------------
            //    o    o/    o     o/    o     o/  
            //  //|   /|   //|    /|   //|    /|   
            //   / \  / \   / \   / \   / \   / \  
            // ------------------------------------
    

    So far, so good. I buid a dll and it works fine in a lot of webs, except the one now - a customer of my uses the MVC-UniBase Concept and in the Partial-View, there are two lines of code, that leads to an error:

    @*Partial View *@
    @Html.RenderCssHere()
    @Html.RenderJsHere()
    

    This two lines, that will usually output a compressed Version of a bundle of js and css files, now just output this after running through my rendering-Code:

    <!--[Css:Name="StandardRenderer"]//-->
    <!--[Javascript:Name="StandardRenderer"]//-->
    

    Expected should be this:

    <link href=\"/DependencyHandler.axd?s=L0FwcC9DU1MvRnJhbWV3b3Jrcy9Cb290c3RyYXAvYm9vdHN0cmFwLm1pbi5jc3M7L3VuaWJhc2UvY3NzL2ZyYW1ld29ya3MvZm9udC1hd2Vzb21lLm1pbi5jc3M7L3VuaWJhc2UvY3NzL2ZyYW1ld29ya3Mvc3dpcGVyLm1pbi5jc3M7L3VuaWJhc2UvY3NzL2ZyYW1ld29ya3MvZmFuY3lib3gvanF1ZXJ5LmZhbmN5Ym94LmNzczsvdW5pYmFzZS9jc3MvQ29sb3JzLmNzczs&amp;t=Css&amp;cdv=7610415\" type=\"text/css\" rel=\"stylesheet\"/><link href=\"https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.5/css/swiper.min.css\" type=\"text/css\" rel=\"stylesheet\"/><link href=\"/DependencyHandler.axd?s=L3VuaWJhc2UvY3NzL2ZyYW1ld29ya3Mva2VuZG8uY29tbW9uLW1hdGVyaWFsLm1pbi5jc3M7L3VuaWJhc2UvY3NzL2ZyYW1ld29ya3Mva2VuZG8ubWF0ZXJpYWwubWluLmNzczsvdW5pYmFzZS9jc3MvZnJhbWV3b3Jrcy9rZW5kby5tYXRlcmlhbC5tb2JpbGUubWluLmNzczs&amp;t=Css&amp;cdv=7610415\" type=\"text/css\" rel=\"stylesheet\"/><link href=\"/App/CSS/App.css?v=85\" type=\"text/css\" rel=\"stylesheet\"/>
    

    Any idea how to fix this?

  • Ruben Meintema 9 posts 100 karma points
    Apr 23, 2020 @ 09:20
    Ruben Meintema
    0

    Hi @Thomas Becket,

    I have the same issue with V8, so it is not specific to V7.

    Any luck yet on finding a solution?

    Cheers,

    Ruben

  • Thomas Beckert 193 posts 469 karma points
    Apr 23, 2020 @ 09:24
    Thomas Beckert
    0

    Unfortunately so far not.

    Using SquishIT Compressor works: https://www.simplethread.com/squishit-the-friendly-aspnet-javascript-and-css-squisher/

    This could be an alternative.

Please Sign in or register to post replies

Write your reply to:

Draft