ASP.NET MVC rendering seems slow

后端 未结 4 1893
北恋
北恋 2021-01-29 22:01

I\'ve created a brand new MVC4 web application in Visual Studio, and done nothing more with it than add a Home controller and a \"Hello world\" index view for it. I then instal

相关标签:
4条回答
  • 2021-01-29 22:36

    Pre-compile the views to speed up the first-time rendering..

    Check the below blog..

    https://blog.deltacode.be/2017/01/08/fix-slow-startup-of-asp-net-mvc-5-on-azure-app-services/

    0 讨论(0)
  • 2021-01-29 22:45

    This could help improve ASP.NET MVC related performance issue , one performance improvement that you can do is to clear all the view engines and add the one(s) that you use. say for ex:- RazorViewEngine. MVC registers 2 view engines by default Webforms and Razor view engines, so clearing and adding the ones that is used alone will improve the look up performance.

    You can add this in global.asax Application_Start.

            ViewEngines.Engines.Clear();    
            ViewEngines.Engines.Add(new RazorViewEngine());      
    

    In order to completely utilize view look up caching and thus again performance gain compile the code in release mode and make sure that your web.config file is configured with <compilation debug="false" /> for view look up caching to kick in.

    0 讨论(0)
  • 2021-01-29 22:48

    Adding to @PSL 's answer - we only ever check for `.CSHTML files

    ViewEngines.Engines.Clear();
    
    IViewEngine razorEngine = new RazorViewEngine() { FileExtensions = new string[] { "cshtml" } };
    
    ViewEngines.Engines.Add(razorEngine);
    

    Also, make sure you are running in Release Mode - that is absolutely critical, as ASP/Razor/MVC 'applies some pretty aggressive caching' when in release mode

    <compilation targetFramework="4.0" debug="false"> in your Web.Config file.

    Sam Saffron/Stack Overflow looked into view rendering performance also:

    http://samsaffron.com/archive/2011/08/16/Oh+view+where+are+thou+finding+views+in+ASPNET+MVC3+

    0 讨论(0)
  • 2021-01-29 22:48

    Views are compiled before use - so on the first occasion they are slow.

    Subsequently they are recompiled if the .cshtml file changes - which means the directories that views are stored in are being monitored. So hard disk speed will be a factor for MVC views.

    Even if they do nothing, each rendering engine checks the hard disk for .cshtml or .aspx files. Since removing a rendering engine made it run twice as fast, I suspect disk speed is the problem:

    • Views are stored on a network drive, or
    • Hard disk is very slow
    0 讨论(0)
提交回复
热议问题