在传统的ASP(或PHP等)ASP.NET MVC包 [英] ASP.NET MVC bundles in Classic ASP (or PHP etc.)

查看:137
本文介绍了在传统的ASP(或PHP等)ASP.NET MVC包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有仍在运行沿ASP.NET MVC传统的ASP应用程序的一部分混合应用。我想用捆绑的JavaScript和样式在传统的ASP也。

We have hybrid application that is still running part of the application with classic ASP along ASP.NET MVC. I would like to use bundled javascript and styles in classic ASP also.

在ASP.NET,我们可以很好地使用捆绑的东西与缓存很好,我们使用Script.Render,增加版本哈希抓取网址。

In ASP.NET we can nicely use bundled stuff with caching nicely, we are using Script.Render, which adds version hash to the fetch url.

事情是,当然这种方法不经典ASP提供。

Thing is that this method of course isn't available in Classic ASP.

我们可以直接使用从HTML &LT捆绑; SCRIPT SRC =包/ JS V =<%=版本%>/> 。版本变量是高速缓存使用破坏传统的ASP变量(强制刷新浏览器)。这是版本之间的变化。

We can use bundled directly from html <script src="bundles/js?v=<%=version%>"/>. version variable is classic ASP variable used in cache busting (force browser refresh). It is changed between versions.

问题是,如果传统的ASP没有给出正确的哈希包请求,MVC捆绑将返回头缓存:不缓存,这将指示浏览器不进行缓存。

Problem is that if classic ASP doesn't give right hash to bundle request, MVC bundling will return header caching: no-caching, which will indicate to browser to not cache it.

你有什么好主意?莫非是散列传统的ASP来计算?你能告诉捆绑,以允许在不V =哈希缓存?难道V =散列从MVC在启动转移?我们有机制来传送经典的ASP和MVC之间的变量,但就是哈希某种方式从MVC启动code可达。

Do you have any good ideas? Could that hash be computed in classic ASP? Could you tell bundling to allow caching without v=hash? Could v=hash be transferred from MVC in startup? We have mechanisms to transfer variables between Classic ASP and MVC, but is that hash some way reachable from MVC startup code.

推荐答案

土豚的野生思想给了我一些想法,我想通了,它自己。解决方法本身是很简单的。

AardVark's wild thought gave me some ideas and I figured out it myself. Solution itself is quite simple.

下面是任何人谁可能需要类似的解决方案的解决方案。

Here is the solution for anyone who might need similar solution.

在您的ASP.NET MVC(Global.asax.cs中或BundleConfig)注册的包:

        List<string> bundleHtml = new List<string>();
        bundleHtml.Add(Scripts.Render("~/bundles/legacybase").ToString());
        bundleHtml.Add(Styles.Render("~/styles/legacycss").ToString());
        File.WriteAllLines(Server.MapPath("~/dyn_legacy_bundle.inc"), bundleHtml, System.Text.Encoding.UTF8);

这将产生一个包含适当的文件dyn_legacy_bundle.inc &LT;脚本方式&gt; 标签都有效,包括版本散列(或调试版本,如果启用调试)

This will generate file dyn_legacy_bundle.inc that contains the proper <script>-tags that include the version hash (or debug versions if debug is enabled).

在经典ASP(或某些淫PHP等):

<head>
   <!--#include file="dyn_legacy_bundle.inc" -->
</head>

这将然后使用已通过ASP.NET启动时产生的文件,并使用捆绑的CSS / JavaScript的。

This will then use the file that was generated on startup by ASP.NET, and use the bundled css/javascript.

负面的事情是,如果捆绑的文件在运行时发生变化,这个动态文件未更新。这将导致束不被缓存。应用程序池回收终将修复缓存,所以我想我们会接受它。让我知道如果你想出办法来避免这一点。

Negative thing is that if bundled files are changed on runtime, this dynamic file is not updated. That will cause bundles not to be cached. App pool recycle will eventually fix caching, so I think we will live with it. Let me know if you figure out way to avoid this.

请注意,这将与任何其他框架的工作也(即PHP)

Notice that this will work with any other framework also (ie. PHP)

这篇关于在传统的ASP(或PHP等)ASP.NET MVC包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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