简体   繁体   English

Umbraco 站点地图 - 错误 CS1525:无效的表达式术语“<”

[英]Umbraco Sitemap - error CS1525: Invalid expression term '<'

Umbraco newbie here. Umbraco 新手在这里。 I'm following the documentation below to create a sitemap in Umbraco 8.1:我正在按照以下文档在 Umbraco 8.1 中创建站点地图:

https://our.umbraco.com/documentation/tutorials/Creating-an-XML-Site-Map/ https://our.umbraco.com/documentation/tutorials/Creating-an-XML-Site-Map/

Everything seems fine but when I try to put live I get the error: error CS1525: Invalid expression term '<'一切看起来都很好,但是当我尝试上线时出现错误:错误 CS1525: Invalid expression term '<'

It seems to not be liking the HTML tags starting at URL - i've tried a few variants on Html.Raw() but it doesn't seem to work.它似乎不喜欢从 URL 开始的 HTML 标签 - 我在 Html.Raw() 上尝试了一些变体,但它似乎不起作用。 Any help appreciated.任何帮助表示赞赏。

 @{ void RenderSiteMapUrlEntry(IPublishedContent node) { var changeFreq = node.Value("searchEngineChangeFrequency", fallback: Fallback.To(Fallback.Ancestors, Fallback.DefaultValue), defaultValue: "monthly"); // with the relative priority, this is a per page setting only, so we're not using recursion, so we won't set Fallback.ToAncestors here and we'll default to 0.5 if no value is set var priority = node.HasValue("searchEngineRelativePriority") ? node.Value("searchEngineRelativePriority") : "0.5"; <url> <loc>@node.Url(mode: UrlMode.Absolute)</loc> <lastmod>@(string.Format("{0:s}+00:00", node.UpdateDate))</lastmod> <changefreq>@changeFreq</changefreq> <priority>@priority</priority> </url> }

not sure what the rest of your code looks like, but from past experience pretty much once in xml mode doesnt like space so when i done this 1 displayed here https://noarlungaunited.com.au/sitemap using pretty much similar code 1st wrapped everything inside elements and used a helper to get the child elements under home and a function to generate the url, see my full code here.不知道你的代码的其余部分是什么样子,但从过去的经验来看,在 xml 模式下几乎有一次不喜欢空间,所以当我这样做时,这里显示的 1 https://noarlungaunited.com.au/sitemap使用非常相似的代码第一次包装元素内的所有内容并使用帮助器获取 home 下的子元素和生成 url 的函数,请参阅我的完整代码here。

 @inherits UmbracoTemplatePage @using umbraco.MacroEngines; @{ Response.ContentType = "text/xml"; var homeNode = Umbraco.TypedContentAtRoot().FirstOrDefault(x => x.ContentType.Alias == "HomePage"); if (homeNode != null && homeNode.TemplateId > 0) { var homepage = new DynamicNode(homeNode.Id); <text><?xml version='1.0' encoding='UTF-8' ?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> <url> <loc>@GetUrlWithDomainPrefix(homeNode.Url)</loc> <lastmod>@(string.Format("{0:s}+00:00", homeNode.UpdateDate))</lastmod> @if (homeNode.GetProperty("sEOSitemapFrequency").HasValue) { <changefreq>@homeNode.GetPropertyValue("sEOSitemapFrequency")</changefreq> } @if (homeNode.GetProperty("sEOSitemapPriority").HasValue) { <priority>@homepage.GetPropertyValue("sEOSitemapPriority")</priority> } </url> @ListChildNodes(homepage) </urlset> </text> } } @helper ListChildNodes(DynamicNode startNode) { const int maxLevelForSiteMap = 100; foreach (DynamicNode node in startNode.ChildrenAsList.Where(x => x.HasAccess && !(x.IsProtected))) { if (node.template > 0) { <url> <loc>@GetUrlWithDomainPrefix(node.Url)</loc> <lastmod>@(string.Format("{0:s}+00:00", node.UpdateDate))</lastmod> @if (!string.IsNullOrEmpty(node.GetProperty("sEOSitemapFrequency").Value)) { <changefreq>@node.GetPropertyValue("sEOSitemapFrequency")</changefreq> } @if (!string.IsNullOrEmpty(node.GetProperty("sEOSitemapPriority").Value)) { <priority>@node.GetPropertyValue("sEOSitemapPriority")</priority> } </url> } if (node.Level <= maxLevelForSiteMap && node.ChildrenAsList.Count() > 0) { @ListChildNodes(node) } } } @functions{ private static string GetUrlWithDomainPrefix(string url) { if (url.StartsWith("/")) url = url.Substring(1); var domainPrefix = string.Format("http://{0}/", HttpContext.Current.Request.ServerVariables["HTTP_HOST"]); if (url.StartsWith(domainPrefix)) return url; else return domainPrefix + url; } }

Resolved.解决。 I was using the code from Umbraco versions 9 & 10 - i'm using 8 so this worked:我使用的是 Umbraco 版本 9 和 10 中的代码 - 我使用的是 8,所以这有效:

https://our.umbraco.com/Documentation/Tutorials/Creating-an-XML-Site-Map/index-v8 https://our.umbraco.com/Documentation/Tutorials/Creating-an-XML-Site-Map/index-v8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM