-1

I am creating sitemap with in ashx file. Getting "Incorrect http header content-type" error when using sitemap checker tool. (https://www.xml-sitemaps.com)

Any idea?

Here is code:

            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;
            }
        }
John Conde
  • 217,595
  • 99
  • 455
  • 496
Mert
  • 99
  • 12
  • I'm voting to close this question as off-topic because Stack Overflow can't help with interfacing with 3rd party APIs. Most likely this issue is because you're providing an incorrect Content-Type header. The service's documentation, and only that source, should be the answer. – gunr2171 Nov 09 '18 at 16:54

1 Answers1

0

Try to change your content type to application/xml

DanB
  • 2,022
  • 1
  • 12
  • 24
  • Well, i have tried to change context.Response.ContentType = "application/xml"; but seems not solved. Well, i checked the browser analizer, type seems still 'document' do you have any idea how can we change? – Mert Nov 09 '18 at 18:32
  • Is this page is public? What is the url? – DanB Nov 09 '18 at 18:43