C# ASP.NET Core 2中的加载速度较慢

C# ASP.NET Core 2中的加载速度较慢,c#,razor,visual-studio-code,asp.net-core-2.0,C#,Razor,Visual Studio Code,Asp.net Core 2.0,我把我现有的应用迁移到了.NETCore2(这真是一件痛苦的事…),但现在看起来一切都正常。然而,我注意到webApp的初始加载和注销非常缓慢。我认为在这两个场景中,服务器正在呈现.cshtml 我取出了应用程序指示灯,这使它有点快,但加载仍然很慢。我也试着不使用kestrel来加载我的https证书,只是让它成为http。这似乎更快,但我需要配置https 有什么解决办法吗?Microsoft文档似乎没有cshtml文件本身的迁移提示 编辑: 我还发现了这条线索: 但不确定如何关闭VS代码中

我把我现有的应用迁移到了.NETCore2(这真是一件痛苦的事…),但现在看起来一切都正常。然而,我注意到webApp的初始加载和注销非常缓慢。我认为在这两个场景中,服务器正在呈现.cshtml

我取出了应用程序指示灯,这使它有点快,但加载仍然很慢。我也试着不使用kestrel来加载我的https证书,只是让它成为http。这似乎更快,但我需要配置https

有什么解决办法吗?Microsoft文档似乎没有cshtml文件本身的迁移提示

编辑:

我还发现了这条线索:

但不确定如何关闭VS代码中的符号。或者如果这是一个相关的问题

编辑2:

我在文档中找到了:

当前在执行操作时,Razor视图预编译不可用 ASP.NET Core 2.0中的自包含部署(SCD)。该功能将 当2.1版本发布时,可用于SCD

这就是我的观点迟钝的原因吗?是否每次都进行渲染/加载

编辑3:

Index.cshtml:

`

@{
ViewData[“标题”]=“我的标题”;
}
@节脚本{
@如果(ViewData[“jwt”]!=null)
{
var-token='@(ViewData[“jwt”].ToString());
setItem(“jwt”,令牌);
}
@如果(ViewData[“appInsightKey”]!=null)
{
var appInsights=window.appInsights | |函数(配置){
函数i(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)}}var t={config:config},u=document,e=window,o=“script”,s=“AuthenticatedUserContext”,h=“start”,c=“stop”,l=“Track”,a=l+“Event”,v=l+“Page”,y=u.createElement(o),r,f;y.src=config.url |”https://az416426.vo.msecnd.net/scripts/a/ai.0.js"u.getElementsByTagName(o)[0].parentNode.appendChild(y);尝试{t.cookie=u.cookie}catch(p){}for(t.queue=[],t.version=“1.0”,r=[“事件”,“异常”,“度量”,“页面视图”,“跟踪”,“依赖项”];r.length;)i(“跟踪”+r.pop());返回i(“设置”+s)、i(“清除”+s)、i(h+a)、i(c+a)、i(h+v)、i(c+v)、i(“刷新配置”;“禁用例外跟踪”[124r]、[f]、r]=函数(config,i,u,e,o){var s=f&&f(config,i,u,e,o);返回s!==!0&&t[“”+r](config,i,u,e,o),s}),t
}({
instrumentationKey:“@(ViewData[“appInsightKey”].ToString())”
});
window.appInsights=appInsights;
appInsights.trackPageView();
}
}
`

编辑4:

我将其缩小到layout.cshtml: 渲染器体和部分看起来非常慢。我会读更多关于它的内容

`

@RenderBody()
@RenderSection(“脚本”,必需:false)
`

编辑:

看起来这条线是它慢的原因


他们正在加载的页面没有更改,大小相同。然而,在1.1中大约需要8秒,而在2中则需要35秒。1.1的加载时间一开始并不理想,但在2中却很荒谬

调试器的代码探查器是怎么说的?@Dai当你说代码探查器时,你是指Visual Studio代码的调试控制台吗?不,我指的是Visual Studio中.NET调试器的性能和探查器功能(不是完全独立的产品“Visual Studio代码”),但是我看到你用VSC标记了你的问题,所以你需要看看那里有哪些功能可以使用。你是直接调试还是连接到正在运行的服务器?如果您直接从VisualStudio运行项目,那么在JIT编译发生时,或者在浏览器缓存所有脚本和样式表时,一开始运行项目的速度总是较慢。尝试将应用程序放入正在运行的IIS应用程序池,并在测量基线之前在浏览器中至少运行每个页面一次。您还可以使用“dotnet build--native”编译为本机代码,以完全避免JIT。是的,我注意到在四处导航后页面速度更快。然而,刷新仍然非常慢,这使我相信它是cshtml呈现@但是,
行似乎很慢。这是一个加载我的项目。使用.NET Core 2时,是否知道webpack/react速度较慢?
@{
    ViewData["Title"] = "MyTitle";
}

<div id="react-app">
     <svg
        class="svg-loader"
        xmlns="http://www.w3.org/2000/svg"
        viewBox="0 0 50 50"
        style="width:60px;height:60px;display:block;margin:100px auto">
        <path d="">
            <animateTransform
                attributeType="xml"
                attributeName="transform"
                type="rotate"
                from="0 25 25"
                to="360 25 25"
                dur="0.6s"
                repeatCount="indefinite"
                />
        </path>
  </svg>
</div>

@section scripts {
  @if (ViewData["jwt"]!=null)
  {
    <script>
      var token = '@(ViewData["jwt"].ToString())';
      localStorage.setItem("jwt", token);
    </script>
  }
  <script src="~/dist/app.js" asp-append-version="true"></script>

  @if (ViewData["appInsightKey"]!=null)
  {
  <script>
   var appInsights=window.appInsights||function(config){
    function i(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},u=document,e=window,o="script",s="AuthenticatedUserContext",h="start",c="stop",l="Track",a=l+"Event",v=l+"Page",y=u.createElement(o),r,f;y.src=config.url||"https://az416426.vo.msecnd.net/scripts/a/ai.0.js";u.getElementsByTagName(o)[0].parentNode.appendChild(y);try{t.cookie=u.cookie}catch(p){}for(t.queue=[],t.version="1.0",r=["Event","Exception","Metric","PageView","Trace","Dependency"];r.length;)i("track"+r.pop());return i("set"+s),i("clear"+s),i(h+a),i(c+a),i(h+v),i(c+v),i("flush"),config.disableExceptionTracking||(r="onerror",i("_"+r),f=e[r],e[r]=function(config,i,u,e,o){var s=f&&f(config,i,u,e,o);return s!==!0&&t["_"+r](config,i,u,e,o),s}),t
    }({
        instrumentationKey: '@(ViewData["appInsightKey"].ToString())'
    });

    window.appInsights=appInsights;
    appInsights.trackPageView();
  </script>
  }
}
    @RenderBody()
    <script src="~/dist/vendor.js" asp-append-version="true"></script>
    @RenderSection("scripts", required: false)
</body>