简体   繁体   中英

Bundling - Application Path error

I use the Microsoft.AspNet.Web.Optimization nuget package for css and js bundling and minification.

I create a bundle in this path ~/bundles/shared.css

BundleTable.Bundles.Add(
    new StyleBundle("~/bundles/shared.css")
       .Include(
        "~/Style/DevexpressAdapter.css",
        "~/Style/Site.css",
        "~/js/jquery-ui-1.10.4.custom/css/flick/jquery-ui-1.10.4.custom.min.css"));

When I run the project on localhost (with CTRL+F5 from Visual Studio) it runs well. If i hit http://localhost/bundles/shared.css then I get the minified and combined css for all the files I have added to the bundle.

But in the published location, it doesn't work.

The site runs at the http://192.168.1.8/MyApp/ address.

when I take a look at the html, the minified bundle's url is src="/MyApp/bundles/shared.css" . But if i hit http://192.168.1.8/MyApp/bundles/shared.css i get a resource not found error. If I also hit http://192.168.1.8/MyApp/MyApp/bundles/shared.css i get the same error.

What is going on, and how do I solve this problem? I can't touch anything at the production server. I can only copy the files to a shared folder I have access to.

It seem's the bundle's url is not resolved correctly. I would expect that the rendered bundle's url would not containt the /MyApp/ part

Instead of providing the virtual path, try using the physical path with following method

Server.MapPath().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM