WebOptimizer icon indicating copy to clipboard operation
WebOptimizer copied to clipboard

Broken if app is deployed to IIS sub application ( virtual dir )

Open dandros opened this issue 6 years ago • 3 comments

In layout I put ~ to resolve app root.

It generates script tag without cache busting param.

dandros avatar Jan 28 '18 19:01 dandros

same with miniblog https://github.com/madskristensen/Miniblog.Core/issues/40

iqmeta avatar Jul 31 '18 06:07 iqmeta

I'm running a test app on a sub domain, if the app has been idling and restarts I get 500s for my bundles (I have to refresh the page) guessing a similar issue?

mjharper84 avatar Oct 02 '18 21:10 mjharper84

I fixed this temporally by adding a customer tag helper that extends the link tag helper. It adds a new attribute on the tag called "RenderRelative". If that attribute is true, it drops the leading '/' to fix for IIS sub apps. It would be nice if a more long term fix were included in the nuget project itself.

public class RelativeRouteLinkTagHelper : LinkTagHelper
{
    public RelativeRouteLinkTagHelper(IWebHostEnvironment env, IMemoryCache cache, IAssetPipeline pipeline, IOptionsMonitor<WebOptimizerOptions> options) : base(env, cache, pipeline, options)
    {
    }

    public override void Process(TagHelperContext context, TagHelperOutput output)
    {
        base.Process(context, output);
        output.Attributes.TryGetAttribute("RenderRelative", out var renderRelative);
        var isTrue = "true".Equals(renderRelative?.Value?.ToString(), StringComparison.CurrentCultureIgnoreCase);
        if (!isTrue) return;
        output.Attributes.TryGetAttribute("href", out var hrefAtr);
        var href = hrefAtr?.Value as string;
        if(!string.IsNullOrEmpty(href))
            output.Attributes.SetAttribute("href", href.TrimStart('/'));
    }
}

JohnTrevorBurke avatar Apr 06 '20 14:04 JohnTrevorBurke