ASP.NET MVC5每个刀片页第一次加载很慢 [英] ASP.NET MVC5 each Razor Page very slow on first load

查看:799
本文介绍了ASP.NET MVC5每个刀片页第一次加载很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是不是当的第一个请求的到达,但是这是每一个基于的Razor视图是首次访问时出现延迟,它可以采取第二或相同的延迟经验二。该视图中的所有后续请求都非常快。发生这种情况即使对于没有做任何形式的方案工作简单视图(如访问数据库等等)。

This is not the same delay experiences when the first request arrives, but this is a delay that is experienced each time a Razor based view is accessed for the first time, it can take a second or two. All subsequent requests to that view are very fast. This happens even for simple views that are not doing any kind of programmatic work (such as accessing a database etc).

我已经确保了在配置文件中调试=假在编译标签下的System.Web。

I've already ensured that debug=false in the compilation tag under system.web in the config file.

我也去掉设置剃须刀作为通过浏览型发动机的Global.asax

I've also removed set Razor as the only view-engine via the Global.asax

什么引起这种延迟吗这似乎是在老asp.net的网站'天经历过它移动到Web应用程序,其中每个.aspx.cs $ C的一个问题$ cbehind在部署,而不是在运行时编译。剃刀是否仍然遭受这样?

What could be causing this delay? This seems like a problem experienced in the old asp.net 'website' days before it moved to a 'web application' where each .aspx.cs codebehind was compiled at deployment rather than at runtime. Does Razor still suffer from this?

推荐答案

该问题是由的剃刀意见解析和编译造成的。一旦意见被编译,它们的执行速度非常快。视图只解析和视图的第一次请求编译或如果视图已自上次编译修改。

The issue is caused by the parsing and compilation of the Razor views. Once views are compiled, they execute very quickly. Views are only parsed and compiled on the first request for the view, or if the view has been modified since the last compile.

您可以通过precompling你的意见,你的发布过程的一部分部署Web应用程序解决此问题。见下面的图片是如何做到这一点在VS2012,使用标准的发布对话框。

You can resolve this on a deployed WebApp by precompling your views as a part of your Publish process. See the image below on how to do it in VS2012, using the standard publish dialog.

如果你愿意,你可以选择更新的选项,但对于生产现场,我不会推荐它。

You can select the updatable option if you wish, but for a production site I wouldn't recommend it.

这篇关于ASP.NET MVC5每个刀片页第一次加载很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆