有没有办法有一个包名称的文件扩展名? [英] Is there any way to have a file extension in a bundle name?

查看:205
本文介绍了有没有办法有一个包名称的文件扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有这样定义一个包:

I would like to have define a bundle like this:

bundles.Add(
    new StyleBundle("~/style.css").Include(
        //...
));

如果包名称只是〜/风格这个工作,但与文件扩展名始终返回404我怀疑服务器搜索CSS和JS该驱动器上的文件,而忽略了捆绑系统,但我找不到任何人谁是试图以包括包名称的文件扩展名。这是可能没有像一个URL重写办?

If the bundle name is just "~/style" this works, but with the file extension it always returns a 404. I suspect the server searches for CSS and JS files on the drive and ignores the bundling system, but I can't find anyone else who is trying to include file extensions in bundle names. Is this possible to do without something like a URL rewrite?

推荐答案

您可以添加以下到你的< system.webServer>在web.config中部分:

You could add the following to your <system.webServer> section in web.config:

<modules runAllManagedModulesForAllRequests="true" />

这将确保静态资源请求,如的.js 的.css 将通过管理模块和ASP.NET MVC被截获。

This will ensure that requests for static resources such as .js and .css will pass through the managed modules and be intercepted by ASP.NET MVC.

作为替代使 runAllManagedModulesForAllRequests 所有请求,你可以只为需要使用的URL配置。所以在&LT;&处理GT; 添加以下内容:

As an alternative to enabling runAllManagedModulesForAllRequests for all requests you could configure them only for the urls you need to use. So inside the <handlers> add the following:

<handlers>
    <!-- ... -->
    <add name="scriptBundle" verb="*" path="script.js" type="System.Web.Optimization.BundleHandler, System.Web.Optimization" preCondition="managedHandler" />
    <add name="cssBundle" verb="*" path="style.css" type="System.Web.Optimization.BundleHandler, System.Web.Optimization" preCondition="managedHandler" />
</handlers>

这篇关于有没有办法有一个包名称的文件扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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