【问题标题】:LD-JSON causes Web application errorLD-JSON 导致 Web 应用程序错误
【发布时间】:2018-07-05 18:09:40
【问题描述】:

我在 .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 设置有关吗?

【问题讨论】:

  • 简单地向视图添加内容不会导致 404。这里还有其他事情发生。
  • @ChrisPratt 是的,我知道,它不应该是 404。我查看了 Windows 中的错误日志和事件错误日志,但什么也没有。我今晚打算把源代码移到服务器上,尝试从VS17运行,看看能不能发现错误。

标签: iis asp.net-core-mvc asp.net-core-2.0 iis-8


【解决方案1】:

当我将代码放入 IDE 后,答案很明显,我忘记在 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>

【讨论】:

    猜你喜欢
    • 2012-04-13
    • 2020-02-06
    • 2020-03-06
    • 2012-02-11
    • 1970-01-01
    • 2017-04-11
    • 1970-01-01
    • 2017-01-03
    • 2013-03-01
    相关资源
    最近更新 更多