asp.net - 将架构添加到 SiteMapPath 控件导致 404 错误
问题描述
以下代码将导致 404 错误。删除代码[itemtype="https://schema.org/BreadcrumbList"],则没有错误但使用面包屑检查器验证页面,它不被识别为面包屑。我可以知道我做错了哪一部分吗?
<asp:SiteMapPath ID="SiteMapPath1" itemtype="https://schema.org/BreadcrumbList" SkipLinkText="" runat="server" >
<NodeTemplate><a itemprop="item" href='<%#Eval("url") %>'><span itemprop="name"><%# Eval("title") %></span></a></NodeTemplate>
</asp:SiteMapPath>
解决方案
asp:SiteMapPath
本身没有itemtype
属性,所以错误(实际上是5xx而不是404)。所以代码应该更详细一点。像这样的东西。
<nav itemscope itemtype="http://schema.org/BreadcrumbList"><%--wrapper--%>
<asp:SiteMapPath ID="SiteMapPath1" runat="server" PathSeparator=" : ">
<NodeTemplate>
<span itemscope itemtype="http://schema.org/ListItem" itemprop="itemListElement"><%--wrapper for each breadcrumb--%>
<meta itemprop="position" content="<%#Container.ItemIndex+1 %>" /> <%--required by Google --%>
<a itemprop="item url" href='<%#Eval("url") %>'>
<span itemprop="name"><%# Eval("title") %></span>
</a>
</span>
</NodeTemplate>
</asp:SiteMapPath>
</nav>
这是生成的 HTML
<nav itemscope itemtype="http://schema.org/BreadcrumbList">
<span id="SiteMapPath1"><a href="#SiteMapPath1_SkipLink"><img alt="Skip Navigation Links" src="/WebResource.axd?d=Ybg6Za1EIYGIkin6VPiwIFL99ITKyu6RhGnxJcLOO8DP1KA0-cdYa4ltoyl-vbOlqsJF4S8oq8kKVCD1XukqME04tF9L2ZSF8XWKW9sT_mc1&t=636668507379463780" width="0" height="0" style="border-width:0px;" /></a><span>
<span itemscope itemtype="http://schema.org/ListItem" itemprop="itemListElement">
<meta itemprop="position" content="1" />
<a itemprop="item url" href='/'><span itemprop="name">home</span></a></span>
</span><span> : </span><span>
<span itemscope itemtype="http://schema.org/ListItem" itemprop="itemListElement">
<meta itemprop="position" content="2" />
<a itemprop="item url" href='my-page.aspx'><span itemprop="name">My Page</span></a></span>
</span><a id="SiteMapPath1_SkipLink"></a></span>
</nav>
通过了谷歌结构化数据测试
推荐阅读
- java - 过滤getAll查询结果
- canvas - 神秘颤振警告:元素被隐式隐藏?
- javascript - 将活动添加到可折叠导航链接
- android - android.view.InflateException: Binary XML file line #15: Error inflating class
- html - UIKit 切换元素默认隐藏
- javascript - 超链接:设置onClick
- javascript - 未捕获的类型错误:无法读取未定义的属性“长度”...?
- python - 尽管有不同的代码,但两个不同的文件给出相同的输出 - PyQT5 和 Python
- ssis - SSIS 使用包部署模型使用项目参数部署带有变量的包
- angularjs - 如何获取 $resource 对象的长度?