top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

check availability of sitemap file in website through ASP.NET

+2 votes
779 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 LinkedIn 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.
...