我有一个包含一个网站使用ASP.NET MVC一个Windows Azure的Web角色。当HTTP请求到达和页第一次加载(的.aspx或.cshtml)被编译的观点而这需要一些时间,因此,第一次一个页供应它需要比以后供同一页显着更长的时间。
我已经启用< MvcBuildViews>
(形容 )执行意见编译时间验证,但似乎并没有对他们的编制有什么影响时,该网站已部署并运行。
Azure的Web角色都有所谓的启动任务,也是一个特殊的的OnStart()
方法,在这里我可以把任何热身code,所以一旦我知道该怎么不要补充说进入角色是没有问题的。
有没有一种方法来强制各方意见汇编?
解决方案原来还有的 ASP.NET precompilation 的,可以使用执行 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.
相关推荐
最新文章