top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

check availability of sitemap file in website through ASP.NET

+2 votes
281 views

I want to check the availability of sitemap.xml and robot.txt file on hosted server and I'm working on SEO project where user put URL and in return the availability of these two file will Show Some Message . Please give me some example

posted May 5, 2014 by Abdul Moeed

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes
 
Best answer

If I understood your question correctly then you require a function in ASP.net which can tell you if a url exist or not. Which can be used to findout for the following url if exist/not exist

<website>/sitemap.xml
<website>/robot.txt

Check this code which would be handy and will return true or false if provided url exist or not exist.

protected bool CheckUrlExists(string url)
    {
        // If the url does not contain Http. Add it.
        if (!url.Contains("http://"))
        {
            url = "http://" + url;
        }
        try
        {
            var request = WebRequest.Create(url) as HttpWebRequest;
            request.Method = "HEAD";
            using (var response = (HttpWebResponse)request.GetResponse())
            {
                return response.StatusCode == HttpStatusCode.OK;
            }
        }
        catch 
        {
            return false;
        }
    }

Please let me know if it does not satisfy your need.

answer May 5, 2014 by Salil Agrawal
thanx... One more thing this is a standard way to find these two files ? and If we found 404 Error what does that Mean ?
From the problem statement I assume that you need the url finder, and this could be one of the simplest way to achieve.
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...