如何强制的ASP.NET MVC的意见汇编? [英] How do I force compilation of ASP.NET MVC views?

查看:296
本文介绍了如何强制的ASP.NET MVC的意见汇编?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一个网站使用ASP.NET MVC一个Windows Azure的Web角色。当HTTP请求到达和页第一次加载(的.aspx或.cshtml)被编译的观点而这需要一些时间,因此,第一次一个页供应它需要比以后供同一页显着更长的时间。

我已经启用< MvcBuildViews> (形容 )执行意见编译时间验证,但似乎并没有对他们的编制有什么影响时,该网站已部署并运行。

Azure的Web角色都有所谓的启动任务,也是一个特殊的的OnStart()方法,在这里我可以把任何热身code,所以一旦我知道该怎么不要补充说进入角色是没有问题的。

有没有一种方法来强制各方意见汇编?

解决方案

原来还有的 ASP.NET precompilation 的,可以使用执行<一href="http://msdn.microsoft.com/en-us/library/system.web.compilation.clientbuildmanager.$p$pcompileapplication%28v=vs.90%29.aspx"相对=nofollow> ClientBuildManager。precompileApplication 并模仿按需编译行为,但只是编译每一页。试了一下 - 在第一次加载看起来特别快

非平凡部分是通过为 ClientBuildManager 构造函数的参数。解决的办法是枚举所有主要用途网​​站对象,并在每个项目。应用枚举所有 .VirtualDirectories 和使用路径 VirtualPath 从每个项目作为参数传递给 ClientBuildManager 的构造。

I have a Windows Azure web role that contains a web site using ASP.NET MVC. When an HTTP request arrives and a page is first loaded the view (.aspx or .cshtml) is compiled and that takes some time and so the first time a page is served it takes notable longer than later serving the same page.

I've enabled <MvcBuildViews> (described in this answer) to enforce compile-time validation of views, but that doesn't seem to have any effect on their compilation when the site is deployed and running.

Azure web roles have so-called startup tasks and also a special OnStart() method where I can place whatever warmup code, so once I know what to do adding that into the role is not a problem.

Is there a way to force compilation of all views?

解决方案

Turns out there's ASP.NET Precompilation that can be performed using ClientBuildManager.PrecompileApplication and mimics the on-demand compilation behavior, but just compiles every page. Tried it - the first load looks notably faster.

The non-trivial part is what to pass as ClientBuildManager constructor parameters. The solution is to enumerate all .Applications of the Site object and for each item in .Applications enumerate all .VirtualDirectories and use Path and VirtualPath from each item as parameters to ClientBuildManager constructor.

这篇关于如何强制的ASP.NET MVC的意见汇编?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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