ASP.Net MVC 5-使用捆绑的JavaScript和CSS部署单独的CDN站点 [英] ASP.Net MVC 5 - Deploy separate CDN site with bundled JavaScript and CSS

查看:98
本文介绍了ASP.Net MVC 5-使用捆绑的JavaScript和CSS部署单独的CDN站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以部署两个ASP.Net MVC站点来执行以下操作.

I was wondering whether it is possible to deploy two ASP.Net MVC sites to do the following.

  1. 主要网站:包含所有控制器和视图
  2. CDN网站:包含所有JavaScript和CSS(第一个站点使用的捆绑JS和CSS)

我期望在解决方案中您将有两个网站项目.我认为在调试模式下这会很好,因为捆绑包名称是一致的.

I was expecting that in the solution you would have two website projects. I think in debug mode this would work fine because the bundle names are consistent.

但是,在不以调试模式运行(在web.config中已关闭)的生产环境中,文件名的查询参数会有所不同,例如 http://www.test-domain.com/bundles/ 引导程序? v = 2Fz3B0iizV2NnnamQFrx-NbYJNTFeBJ2GM05SilbtQU1 (其中 bootstrap 是捆绑包的名称).

However, in production where you are not running in debug mode (turned off in web.config), the file names have a query parameter that varies e.g. http://www.test-domain.com/bundles/bootstrap?v=2Fz3B0iizV2NnnamQFrx-NbYJNTFeBJ2GM05SilbtQU1 (where bootstrap is the name of the bundle).

有人知道如何从主网站的Razor视图中引用CDN网站中的捆绑软件吗?

Does anyone know how to reference the bundles in the CDN website from the Razor views in the main website?

答案 我意识到您不必为捆绑包名称包含查询参数

Answer I realised that you don't have to include the query parameter for bundle name

推荐答案

如果您的MVC 5项目在本地计算机上的 Release 模式下运行良好,那么它也将在Production上运行.

If your MVC 5 project work well in Release mode in your local machine, it will work on Production too.

在生产上需要注意的其他几点是:

Only few more considerations you need to take care on production are :

  • 请确保已启用 CORS ,因为您有js&不同站点的css资源(如果域名不同)

  • Make sure CORS is enabled since you have js & css resources at different site(if domain name is different)

确保您在具有托管视图的MVC5网站上引用&后端逻辑具有您在 CDN

Make sure you references at MVC5 site having hosting views & back-end logic have correct references as you have created in CDN

允许防火墙/托管端口在两台托管计算机上进行通信.

Firewall/hosting port is allowed on both hosting machine to communicate.

希望这会有所帮助.

附加到URL末尾的BTW查询字符串只是确保服务器对每个请求的服务方式不同,而不是像缓存一样,不会影响您的应用程序.

BTW querystring appended to end of URL just make sure every request is differently served by Server not as cached, nothing to impact your application.

这篇关于ASP.Net MVC 5-使用捆绑的JavaScript和CSS部署单独的CDN站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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