asp.net xml 站点地图不正确的 http header 内容
asp.net xml sitemap incorrect http header content
我正在使用 ashx 文件创建站点地图。使用站点地图检查工具时出现 "Incorrect http header content-type" 错误。 (https://www.xml-sitemaps.com)
有什么想法吗?
代码如下:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/xml";
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetAllowResponseInBrowserHistory(true);
using (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("priority", "1.0");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
context.Response.End();
}
}
public bool IsReusable
{
get
{
return false;
}
}
尝试将您的内容类型更改为 application/xml
我正在使用 ashx 文件创建站点地图。使用站点地图检查工具时出现 "Incorrect http header content-type" 错误。 (https://www.xml-sitemaps.com)
有什么想法吗?
代码如下:
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/xml"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Cache.SetCacheability(HttpCacheability.NoCache); context.Response.Cache.SetAllowResponseInBrowserHistory(true); using (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("priority", "1.0"); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); context.Response.End(); } } public bool IsReusable { get { return false; } }
尝试将您的内容类型更改为 application/xml