asp.net xml网站地图不正确的HTTP标头内容

时间:2018-11-09 16:49:00

标签: c# asp.net sitemap google-sitemap web.sitemap

我正在使用ashx文件创建站点地图。使用站点地图检查器工具时出现“错误的http标头内容类型”错误。 (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;
            }
        }

1 个答案:

答案 0 :(得分:0)

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