加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 23:41:08 所属栏目:asp.Net 来源:网络整理
导读:我有一个Windows Azure网站角色,其中包含一个使用ASP.NET MVC的网站.当HTTP请求到达并且首先加载页面时,视图(.aspx或.cshtml)被编译,并且需要一些时间,所以在第一次提供页面时,它比以后提供相同的页面要长. 我启用了 MvcBuildViews (描述为in this answer)来
我有一个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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读