Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect CSS virtual path to absolute path transformation #9

Closed
jahav opened this issue Sep 1, 2015 · 1 comment
Closed

Incorrect CSS virtual path to absolute path transformation #9

jahav opened this issue Sep 1, 2015 · 1 comment

Comments

@jahav
Copy link

jahav commented Sep 1, 2015

Hello,
we have an app that is running in the server/MyApp path.

We are using System.Web.Optimization.CssRewriteUrlTransformFixed() to transform URL, but because we are not in root, but MyApp path, relative paths are resolved incorrectly.

Basically
we have something like

var urlTransform = new System.Web.Optimization.CssRewriteUrlTransformFixed();
bundles.Add(new LessBundle("~/Shared/CSS/common")
    .CheckAndInclude("~/Shared/CSS/external/jquery-ui/jquery-ui.css", urlTransform));

and in jquery-ui.css is

.ui-widget-content {
    background: url("images/ui.png");
}

and the transformed URL in CSS is

/Shared/CSS/external/jquery-ui/images/ui.png

instead of

/MyApp/Shared/CSS/external/jquery-ui/images/ui.png

See also http://aspnetoptimization.codeplex.com/workitem/83 and http://stackoverflow.com/a/17702773/2622707.

As a workaround we are using a copy as CssRewriteUrlTransformFixed with following line

var directory = "~" + VirtualPathUtility.GetDirectory(includedVirtualPath.Substring(1));

although I think would work as well

var directory = VirtualPathUtility.GetDirectory(includedVirtualPath);

Is there some reason for stripping tilda from path? If not, would it be possible to fix this?

Thank you very much.

@benmccallum
Copy link
Owner

Hi @jahav,

Sorry it has taken me so long to get to this. I have updated the codebase with your suggested fix of removing the .Substring(1), as the VirtualPathUtility methods should handle both scenarios. Thanks for the thorough issue report!

I've release to NuGet the fix as version 2.0.3.
https://www.nuget.org/packages/AspNetBundling/2.0.3

Cheers,
Ben

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants