如何强制编译ASP.NET MVC视图?

前端之家收集整理的这篇文章主要介绍了如何强制编译ASP.NET MVC视图?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个Windows Azure网站角色,其中包含一个使用ASP.NET MVC的网站.当HTTP请求到达并且首先加载页面时,视图(.aspx或.cshtml)被编译,并且需要一些时间,所以在第一次提供页面时,它比以后提供相同的页面要长.

我启用了< MvcBuildViews> (描述为in this answer)来实施视图的编译时验证,但是当站点部署和运行时,它们似乎没有影响它们的编译.

Azure Web角色有所谓的启动任务,还有一个特殊的OnStart()方法,我可以放置任何加热代码,所以一旦我知道如何添加到角色中就不是一个问题.

有没有办法强制汇编所有意见?

解决方法

看看 Precompiled Razor Views by David Ebbo

Why would you want to do that?

One reason to do this is to avoid any runtime hit when your site
starts,since there is nothing left to compile at runtime. This can be
significant in sites with many views.

Also,you no longer need to deploy the cshtml files at all,resulting
in a smaller deployment file set.

Another cool benefit is that it gives you the ability to unit test your views,which has always been something very difficult with the standard runtime compilation model. I’ll cover that in more details in a future post.

猜你在找的asp.Net相关文章