我们在我们的站点中使用MVC Bundling,CssRewriteUrlTransform
确保图像URL在动态bundle css文件中工作.
但这只适用于不使用虚拟目录的情况,即
http://localhost/VirttualDir
不行,但http://localhost/
确实如此.这是因为CssRewriteUrlTransform
在重写URL时,转换不会考虑虚拟文件夹.因此,如果图像真实路径是localhost/vdir/content/img/foo.png
它将重写它localhost/content/img/foo.png
是错误的
从一个全新的ASP.NET MVC 4 Beta Web应用程序,我正在重新安排我的文件夹以匹配Rob Conery的VidPub.Web示例
具体来说,这意味着内容的最终目录结构如下所示
VidPub.Web | ---Public | |---Images |--- *.png |---javascripts |--- *.js |---stylesheets |----themes |---base |--- images |--- *.css |----site.css
但是,当我更改以下行时 _Layout.cshtml
<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
"~/Content/css")"
rel="stylesheet"
type="text/css" />
<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
"~/Content/themes/base/css")"
rel="stylesheet"
type="text/css" />
<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
"~/Scripts/js")"></script>
Run Code Online (Sandbox Code Playgroud)
至
<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
"~/Public/stylesheets/css")"
rel="stylesheet"
type="text/css" />
<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
"~/Public/stylesheets/themes/base/css")"
rel="stylesheet"
type="text/css" />
<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
"~/Public/javascripts/js")"></script>
Run Code Online (Sandbox Code Playgroud)
在最终的HTML中,我最终没有任何结果.
<link rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" />
<script></script>
Run Code Online (Sandbox Code Playgroud)
为什么不在新位置拾取文件?
我试图弄清楚为什么当我创建一个脚本包引用我的主站点的应用程序文件夹下的IIS VirtualDirectory中的文件时,为什么它不会输出任何内容.
我发现这篇文章:
为什么ResolveBundleUrl不适用于自定义文件夹?(MVC Beta 4)
但是对于System.Web.Optimization的最新beta版本,它似乎不再有效.
据我所知,答案是否定的.我看到的问题来自课堂上的Include(params string[])
方法System.Web.Optimization.Bundle
.在内部调用System.Web.Optimization.IncludeDirectory(string, string, bool)
,然后使用此代码:
DirectoryInfo directoryInfo = new DirectoryInfo(
HttpContext.Current.Server.MapPath(directoryVirtualPath));
Run Code Online (Sandbox Code Playgroud)
虽然可以HttpContext.Current
在单元测试期间设置,但我无法弄清楚如何使其.Server.MapPath(string directoryVirtualPath)
返回非空字符串.由于DirectoryInfo(string)
构造函数在传递null参数时抛出异常,因此这样的测试将始终失败.
.NET团队对此有何建议?我们是否必须将捆绑配置作为集成测试或用户验收测试的一部分进行单元测试?
unit-testing asp.net-mvc-4 bundling-and-minification asp.net-optimization
我在IIS服务器虚拟目录上托管多个应用程序,我正在使用URL Rewrite来方便它们.像这样手动编写的所有图像和其他资源"~/path/to/my/content"
都有正确的输出"/path/to/my/content"
,但是束路径之类"~/client/js"
的输出"/myapplication/client/js"
应该是"/client/js"
.
我该如何解决这个问题?
我如何启动脚本包:
var scriptBundle = new ScriptBundle("~/client/js");
Run Code Online (Sandbox Code Playgroud)
重写配置:
<rule name="Official Website" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" matchType="Pattern" pattern="^(www\.)?domain\.com$" ignoreCase="true" negate="false" />
</conditions>
<action type="Rewrite" url="officialsite/{R:1}" />
</rule>
Run Code Online (Sandbox Code Playgroud)
正在调查这些主题,但无法让任何事情对我有用:
更新:我使用Winhost作为托管服务提供商,他们不支持为IP设置主机头,可能是由于共享IP.它们提供了根文件夹的域指针,这就是我使用URL重写的原因.
asp.net-mvc iis-7 url-rewriting virtual-directory bundling-and-minification