我在服务器端使用HeadOutlet预渲染net6.0应用程序来设置一些头标签,如Meta描述,但服务器首先渲染应用程序,然后是头,这使得搜索引擎忽略它。
@page "/"
@namespace Example.Pages
@using Microsoft.AspNetCore.Components.Web
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = null;
}
<!DOCTYPE html>
<html lang="en">
<head>
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
<base href="~/" />
<link href="css/site.css" rel="stylesheet" />
<link rel="preconnect" href="https://fonts.gstatic.com">
</head>
<body>
<component type="typeof(App)" render-mode="ServerPrerendered" />
<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
<a href="/" class="reload">Reload</a>
<a href="#" class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.server.js"></script>
<script src="~/outsideHandleContainerJsInterop.js"></script>
</body>
</html>
个字符
在浏览器中查看页面将按照预期在头部呈现Meta标记,但在失眠/ Postman 中执行get请求将返回初始头部和blazor预呈现标记注解
<!--Blazor:{"sequence":0,"type":"server","prerenderId":"b0376004567c4aaf9c07defc4341e21e","descriptor":"<long string here>"}--><!--Blazor:{"prerenderId":"b0376004567c4aaf9c07defc4341e21e"}-->
型
这是一个错误还是我错过了什么?我需要头部之前或与页面的其余部分呈现,以便搜索引擎可以拿起它。
2条答案
按热度按时间laawzig21#
这是通过将html/head/body从_Host.cshtml移动到_Layout. html来解决的。更多信息在这篇文章中描述:https://github.com/dotnet/aspnetcore/issues/37293
hkmswyz62#
我没有一个_Layout文件。我没有移动,而是在_Host文件中完全限定了HeadOutlet的类并使其工作。
字符串