asp.net - ASP.NET View 编译的频率和时间

标签 asp.net asp.net-mvc

我尝试从 MSDN 和 google 获取答案,但找不到。

我正在致力于 MVC 应用程序的性能优化,这需要了解 View 编译。

  1. asp.net MVC View 何时编译?
  2. 所有 View 都会在应用程序启动时或每次请求时进行编译吗?
  3. 我假设编译的 View 会被使用,直到应用程序池重新启动。这是正确的吗?

最佳答案

When does asp.net mvc views get compiled?

当第一个请求命中并执行返回 View 的操作时,将编译 View 。

All views gets compiled on application start up or on each request?

没有。不在应用程序启动时。不是针对每个请求。如果请求A返回查看V1。 V1 已编译。然后,如果请求 B 到达并需要相同的 View V1,则仅返回该 View ,而无需重新编译它。

I assume the compiles views get used until app pool restart?

不,它们仅编译一次,并且在应用程序池重新启动时不会重新编译。

为什么不在发布应用程序之前预编译您的 View ?

您可以在构建应用程序时预编译 MVC View 。因此,您需要卸载 MVC 项目并修改以下 XML 元素

<MvcBuildViews>false</MvcBuildViews>

对此:

<MvcBuildViews>true</MvcBuildViews>

更新:

正如Nil Pun在我的答案的评论中发现的那样,以下link打破了关于 csproj 文件中 MvcBuildViews 元素的神话。

那篇文章的作者说:

MvcBuildViews is here to make building of views as part of web application building process. It doesn’t generate any output to binaries folder. Views are precompiled during publishing process and precompiling happens only if views are not expected to be modified. It is possible to configure how precompilation is done. This way it is possible to merge binaries of precompiled views to one assembly.

关于asp.net - ASP.NET View 编译的频率和时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43714445/

相关文章:

javascript - 如何在javascript函数中获取列表框项目引用

asp.net-mvc - 如何在 ASP.NET MVC 项目中获取 "Add Controller"和 "Add View"菜单选项?

javascript - 如何将我的 javascript 文件加载到嵌套在 View 中的局部 View 中? MVC5

mysql - 在 AppHarbour 中托管 MVC 应用程序

c# - 路由 ASP.NET Core 5 - id 的默认值总是返回 0

asp.net - 是否有推荐的方法使用 ASP.NET Web API 返回图像

asp.net - 即使注销后,我也可以使用“返回”按钮返回主页!

c# - 从其他用户控件加载用户控件 (ascx)

jquery - ASP.NET MVC 2 使用 EnableClientValidation() 时验证带有数据注释异常的强类型模型列表

c# - RadListView ItemCommand 未触发