gpt4 book ai didi

asp.net - 根据 index.cshtml 的 HTML 响应

转载 作者:行者123 更新时间:2023-12-02 01:02:35 25 4
gpt4 key购买 nike

我正在开发一个使用 VS 2107 模板构建的 Angular SPA。模板解决方案默认使用 Webpack。运行此应用程序时,我从服务器收到以下响应:

<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MySite</title>
<base href="/" />

<link rel="stylesheet" href="/dist/vendor.css?v=GTBoa19X9IFhaihx7ZAnVru_FAmBl9DrU8hiEInbZsk" />
<script type="text/javascript">
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: 'ba5fc891-eb8c-4a6d-9126-d79556ae0863'
});

window.appInsights=appInsights;
appInsights.trackPageView();

</script>
</head>
<body>

<app></app>

<script src="/dist/vendor.js?v=ktEYx3Pf8jICUgoPuQqu7uGMM9Su7Hv398WJvv9P2o4"></script>

<script src="/dist/main-client.js?v=sEZxwQM4sP47PpPCDWohUTvZ02wu6JusYOT7VGzPDdo"></script>

</body>
</html>

body's content 确实有意义,因为 index.cshtml 是:

@{
ViewData["Title"] = "Home Page";
}

<app></app>

<script src="~/dist/vendor.js" asp-append-version="true"></script>
@section scripts {
<script src="~/dist/main-client.js" asp-append-version="true"></script>
}

但是,head 根本没有意义。 如何使用 vendor.cssappInsights 脚本 填充Webpack 是否负责包含 vendor.css?我猜不是,因为它负责构建 vendor.css 但是将它包含在我们得到的 HTML 中呢?

最佳答案

vendor.css_Layout.cshtml 设置。 vendor.csswebpack 生成。它由 msbuild 运行。看一下,找到.csproject你会发现是这样的:

<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" />
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
<Exec Command="node node_modules/webpack/bin/webpack.js --env.prod" />

<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="wwwroot\dist\**; ClientApp\dist\**" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>
</ItemGroup>
</Target>

Angular-Donet 是通用的SSR(服务器端渲染)。参见 here .

AppInsight 由 visual studio 设置用于开发目的,请参阅 here .如果您使用的是 vscode,则不会设置。

关于asp.net - 根据 index.cshtml 的 HTML 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49559499/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com