【问题标题】:asp.net xml sitemap incorrect http header contentasp.net xml 站点地图不正确的 http 标头内容
【发布时间】:2018-11-09 16:49:00
【问题描述】:

我正在使用 ashx 文件创建站点地图。使用站点地图检查器工具时出现“不正确的 http 标头内容类型”错误。 (https://www.xml-sitemaps.com)

有什么想法吗?

代码如下:

公共无效ProcessRequest(HttpContext上下文) { context.Response.ContentType = "文本/xml"; context.Response.ContentEncoding = 编码.UTF8; context.Response.Cache.SetCacheability(HttpCacheability.NoCache); context.Response.Cache.SetAllowResponseInBrowserHistory(true); 使用 (writer = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8)) { writer.WriteStartDocument(); writer.WriteStartElement("urlset"); writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9"); writer.WriteStartElement("url"); writer.WriteElementString("loc", "https://website.com"); writer.WriteElementString("lastmod", string.Format("{0:yyyy-MM-dd}", currentTime)); writer.WriteElementString("changefreq", "weekly"); writer.WriteElementString("优先级", "1.0"); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); context.Response.End(); } } 公共布尔 IsReusable { 得到 { 返回假; } }

【问题讨论】:

  • 我投票决定将此问题作为离题结束,因为 Stack Overflow 无法帮助与第 3 方 API 进行交互。这个问题很可能是因为您提供了不正确的 Content-Type 标头。服务的文档,只有那个来源,应该是答案。

标签: c# asp.net xml-sitemap


【解决方案1】:

尝试将您的内容类型更改为application/xml

【讨论】:

  • 好吧,我已经尝试改变 context.Response.ContentType = "application/xml";但似乎没有解决。好吧,我检查了浏览器分析器,类型似乎仍然是“文档”,你知道我们该如何改变吗?
  • 这个页面是公开的吗?网址是什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
相关资源
最近更新 更多