ASP MVC-捆绑包创建目录路径而不是文件路径 [英] ASP MVC - Bundles creating directory path instead of file path

查看:94
本文介绍了ASP MVC-捆绑包创建目录路径而不是文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个:

bundles.Add(new StyleBundle("~/Content/Styles/Default").Include("~/Content/Styles/Default/Site.css"));

它创建了这个:

<link href="/Content/Styles/Default?v=HG5hShy6_NaqI7SUDWQuc6zijexRxZooKF4ayIgK5tY1" rel="stylesheet">

现在,我在Web服务器上启用了目录浏览,当我单击该样式路径时,它会将我移动到目录而不是文件!为什么?

Now, i enabled directory browsing on my webserver, and when I click that style path, it moves me to a directory, and not to a file! Why?

更新:我仍然没有解决这个问题,当我在链接http://myserver/Content/Styles/Default?v=HG5hShy6_NaqI7SUDWQuc6zijexRxZooKF4ayIgK5tY1上访问时,得到的只是文件列表(如ftp)

Update: I still did not manage to solve that question, all i get when i go on the link http://myserver/Content/Styles/Default?v=HG5hShy6_NaqI7SUDWQuc6zijexRxZooKF4ayIgK5tY1 is a list of files (like on a ftp)

推荐答案

首先查看此

捆绑是ASP.NET 4.5中的一项新功能,可以轻松组合 或将多个文件捆绑为一个文件.您可以创建CSS, JavaScript和其他捆绑软件.较少的文件意味着较少的HTTP请求 这样可以提高首页加载性能.

Bundling is a new feature in ASP.NET 4.5 that makes it easy to combine or bundle multiple files into a single file. You can create CSS, JavaScript and other bundles. Fewer files means fewer HTTP requests and that can improve first page load performance.

请求

http://localhost/MvcBM_time/bundles/AllMyScripts?v=r0sLDicvP58AIXN_mc3QdyVvVj5euZNzdsa2N1PKvb81

用于捆绑包AllMyScripts,并包含查询字符串对 v = r0sLDicvP58AIXN_mc3QdyVvVj5euZNzdsa2N1PKvb81.

is for the bundle AllMyScripts and contains a query string pair v=r0sLDicvP58AIXN_mc3QdyVvVj5euZNzdsa2N1PKvb81.

查询字符串v具有 一个值令牌,它是用于缓存的唯一标识符.只要 捆绑包不变,ASP.NET应用程序将请求 AllMyScripts使用此令牌捆绑.捆绑中是否有文件 更改后,ASP.NET优化框架将生成一个新令牌, 保证浏览器对包的请求将获得最新的 捆绑包

The query string v has a value token that is a unique identifier used for caching. As long as the bundle doesn't change, the ASP.NET application will request the AllMyScripts bundle using this token. If any file in the bundle changes, the ASP.NET optimization framework will generate a new token, guaranteeing that browser requests for the bundle will get the latest bundle

这是添加文件目录的方法

This is how to add directory with files

bundles.Add(new StyleBundle("~/jQueryUI/themes/baseAll")
    .IncludeDirectory("~/Content/themes/base", "*.css"));

这是添加多个文件的方法:

This is how to add multiple files:

bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
          "~/Content/themes/base/jquery.ui.core.css",
          "~/Content/themes/base/jquery.ui.resizable.css",
          "~/Content/themes/base/jquery.ui.selectable.css",
          "~/Content/themes/base/jquery.ui.accordion.css",
          "~/Content/themes/base/jquery.ui.autocomplete.css",
          "~/Content/themes/base/jquery.ui.button.css",
          "~/Content/themes/base/jquery.ui.dialog.css",
          "~/Content/themes/base/jquery.ui.slider.css",
          "~/Content/themes/base/jquery.ui.tabs.css",
          "~/Content/themes/base/jquery.ui.datepicker.css",
          "~/Content/themes/base/jquery.ui.progressbar.css",
          "~/Content/themes/base/jquery.ui.theme.css"));

这篇关于ASP MVC-捆绑包创建目录路径而不是文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆