首页 > 解决方案 > LD-JSON 导致 Web 应用程序错误

问题描述

我有一个在 .netcore 2.0 中创建的网站,当我将 schema.org 标记添加到网站时,它会为网站返回 404 错误。

例如在正文底部添加以下代码

<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type": "WebSite",
    "url": "http://website.com",
    "name": "wbs",
    "description": "Web Studio"
}
</script>

它返回 404 错误。如果我删除该 ld-json,那么网站将正常运行。

我将网站托管在运行 IIS 8 的 Windows 服务器机器上;与 IIS 设置有关吗?

标签: iisasp.net-core-mvcasp.net-core-2.0iis-8

解决方案


一旦我将代码放入 IDE 中,答案就很明显了,我忘记了躲避@in razor。

所以代码

<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type": "WebSite",
    "url": "http://website.com",
    "name": "wbs",
    "description": "Web Studio"
}
</script>

会成为:

<script type="application/ld+json">
{
    "@@context": "http://schema.org",
    "@@type": "WebSite",
    "url": "http://website.com",
    "name": "wbs",
    "description": "Web Studio"
}
</script>

推荐阅读