gpt4 book ai didi

asp.net - 如何强制编译 ASP.NET MVC View ?

转载 作者:行者123 更新时间:2023-12-03 14:42:29 24 4
gpt4 key购买 nike

我有一个 Windows Azure Web 角色,其中包含一个使用 ASP.NET MVC 的网站。当 HTTP 请求到达并且页面首次加载时, View (.aspx 或 .cshtml)将被编译,这需要一些时间,因此第一次提供页面所需的时间比后来提供同一页面所需的时间要长得多。

我已启用 <MvcBuildViews> (描述 in this answer )强制 View 的编译时验证,但这似乎对站点部署和运行时的编译没有任何影响。

Azure Web 角色有所谓的启动任务,还有一个特殊的 OnStart()我可以在其中放置任何预热代码的方法,因此一旦我知道该怎么做,将其添加到角色中就不是问题了。

有没有办法强制编译所有 View ?

最佳答案

看看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 - 如何强制编译 ASP.NET MVC View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10618600/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com